@using BlazorApp.Data;

<p>
    Users: <b>@this.Users.Count</b>
</p>

<br />

<Counter></Counter>

<ul class="list-group">
    @foreach (UserData user in this.Users)
    {
        <li @key="user" class="list-group-item">
            <button class="btn btn-link" type="button" @onclick="(() => KickUser(user))">[Kick]</button>
            <label style="color:@this.Color">@user.Name</label>
        </li>
    }
</ul>

@code {
    [CascadingParameter(Name = "ThemeColor")]
    public string Color { get; set; }


    [Parameter]
    public List<UserData> Users { get; set; }

    [Parameter]
    public EventCallback Callback { get; set; }

    protected override void OnInitialized()
    {
        this.Users.Add(new UserData() { Name = "Simpson" });
        this.Users.Add(new UserData() { Name = "Richard" });
        this.Users.Add(new UserData() { Name = "Tylor" });
    }

    public void AddUser(UserData user)
    {
        this.Users.Add(user);
    }

    public void KickUser(UserData user)
    {
        this.Users.Remove(user);

        if (this.Callback.HasDelegate)
            this.Callback.InvokeAsync();
    }
}
