@using LANCommander.Data.Enums
@using LANCommander.Data.Models

<MudTable Items="@Game.MultiplayerModes" Elevation="0" Dense="true">
    <HeaderContent>
        <MudTh>Type</MudTh>
        <MudTh>Min Players</MudTh>
        <MudTh>Max Players</MudTh>
        <MudTh>Description</MudTh>
        <MudTh></MudTh>
    </HeaderContent>

    <RowTemplate>
        <MudTd>
            <MudSelect @bind-Value="context.Type" Margin="0">
                @foreach (MultiplayerType type in Enum.GetValues(typeof(MultiplayerType)))
                {
                    <MudSelectItem Value="@((MultiplayerType)type)">@type</MudSelectItem>
                }
            </MudSelect>
        </MudTd>
        <MudTd><MudNumericField @bind-Value="context.MinPlayers" Margin="0" /></MudTd>
        <MudTd><MudNumericField @bind-Value="context.MaxPlayers" Margin="0" /></MudTd>
        <MudTd><MudTextField @bind-Value="context.Description" Margin="0" /></MudTd>
        <MudTd Class="d-flex justify-end">
            <MudIconButton Color="Color.Error" OnClick="() => RemoveMode(context)" Icon="@Icons.Material.Filled.Close"></MudIconButton>
        </MudTd>
    </RowTemplate>
</MudTable>

<MudPaper Elevation="0" Class="d-flex justify-end mt-3">
    <MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="AddMode">Add</MudButton>
</MudPaper>

@code {
    [Parameter] public Game Game { get; set; }

    private void AddMode()
    {
        if (Game.MultiplayerModes == null)
            Game.MultiplayerModes = new List<MultiplayerMode>();

        Game.MultiplayerModes.Add(new MultiplayerMode());
    }

    private void RemoveMode(MultiplayerMode mode)
    {
        Game.MultiplayerModes.Remove(mode);
    }
}
