@page "/ProductLines/Index"

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

@inject ProductLineService productLineService

<h1>ProductLines</h1>

@if (productLines is null)
{
    <p><em>Loading... !</em></p>
}
else
{
    <p>Es wurden @productLines.Count ProductLines gefunden.</p> 
    @if (productLines != null)
    {
        <DataGrid 
            TItem="ProductLine" 
            Data="@productLines" 
            @bind-SelectedRow="@selectedProductLine"
            PageSize="10"
            ShowPager
            Bordered
            Hoverable
            Striped
            Responsive>
        <DataGridCommandColumn />
                <DataGridColumn Field="@nameof(ProductLine.ProductLineCode)" Caption="ProductLineNumber"/>
                <DataGridColumn Field="@nameof(ProductLine.ProductLineDescription)" Caption="ProductLineDescription" Editable />
        </DataGrid>

        <p>ProductLine @selectedProductLine.ProductLineCode selected.</p>                
    }
}

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

    ProductLine selectedProductLine = new();
    List<ProductLine> productLines = new();

    protected override async Task OnParametersSetAsync()
    {
        productLines = await Task.Run(() => productLineService.GetAllProductLinesAsync());
        selectedProductLine = productLines.FirstOrDefault()!;
    }
}