@page "/user"

@using BlazorApp.Data;

<h3>Online Users</h3>

<ShowUser @ref="_showUser" Users="_users" Callback="CallbackAction"/>

<br />

<div class="container">
    <div class="row">
        <div class="col">
            <input class="form-control" placeholder="Add User" @bind-value="_inputName"/>
        </div>
        <div class="col">
            @* 속성(Attribute)도 binding 가능 *@
            @* conditional atribute 속성 자체에도 조건 붙일 수 있음 *@
            <button class="btn btn-primary" type="button" @onclick="AddUser" disabled="@(_users.Count >= 5)">Add a user</button>
        </div>
    </div>
</div>

@code {
    private List<UserData> _users = new List<UserData>();
    private ShowUser _showUser;

    private string _inputName;

    private void AddUser()
    {
        if (string.IsNullOrEmpty(_inputName))
            return;

        _showUser.AddUser(new UserData() { Name = _inputName });
        _inputName = "";
    }

    private void KickUser(UserData user)
    {
        _showUser.KickUser(user);
    }

    private void CallbackAction()
    {
        _inputName = "Callback Action Called!";
    }
}
