@page "/AccountTypes/Index"

@using Gremlin_BlazorServer.Data.EntityClasses;
@using Gremlin_BlazorServer.Services;
@using System.Globalization;
@using System.Diagnostics;

@inject AccountTypeService accountTypeService

<h1>AccountTypes</h1>

@if (accountTypes is null)
{
    <p><em>Loading... !</em></p>
}
else
{
    <p>Es wurden @accountTypes.Count AccountTypes gefunden.</p> 
    @if (accountTypes != null)
    {
        <DataGrid 
            TItem="AccountType" 
            Data="@accountTypes" 
            @bind-SelectedRow="@selectedAccountType"
            PageSize="10"
            ShowPager
            Bordered
            Hoverable
            Striped
            Responsive>
        <DataGridCommandColumn />
                <DataGridColumn Field="@nameof(AccountType.AccountTypeCode)" Caption="AccountTypeNumber"/>
                <DataGridColumn Field="@nameof(AccountType.AccountTypeDescription)" Caption="AccountTypeDescription" Editable />
        </DataGrid>

        <p>AccountType @selectedAccountType.AccountTypeCode selected.</p>                
    }
}

@code {
    public string searchAccountType = string.Empty;
    CultureInfo cultureInfo = new("de-DE");

    AccountType selectedAccountType = new();
    List<AccountType> accountTypes = new();

    protected override async Task OnParametersSetAsync()
    {
        accountTypes = await Task.Run(() => accountTypeService.GetAllAccountTypesAsync());
        selectedAccountType = accountTypes.FirstOrDefault()!;
    }
}