@page "/list"
@using myBlazorApp.Models;


<h3>@Localizer["Title"]</h3>

<div>
    <NavLink style="background-color: #F5FFFA; color: blue; border-color: #3B8526 " class="btn btn-primary" href="Add" Match="NavLinkMatch.All">
        <i class="fa fa-plus"></i> Ajouter
    </NavLink>
</div>

<DataGrid TItem="Item"
          Data="@items"
          ReadData="@OnReadData"
          TotalItems="@totalItem"
          PageSize="10"
          ShowPager
          Responsive>
    <DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="#" />
    <DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image">
        <DisplayTemplate>
            @if (!string.IsNullOrWhiteSpace(context.ImageBase64))
            {
                <img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="min-width: 50px; max-width: 150px" />
            }
            else
            {
                <img src="images/default.png" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="max-width: 150px" />
            }
        </DisplayTemplate>
    </DataGridColumn>
    <DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Nom" />
    <DataGridColumn TItem="Item" Field="@nameof(Item.StackSize)" Caption="Taille Stack" />
    <DataGridColumn TItem="Item" Field="@nameof(Item.MaxDurability)" Caption="Durabilité Max" />
    <DataGridColumn TItem="Item" Field="@nameof(Item.EnchantCategories)" Caption="Catégories d'enchantement">
        <DisplayTemplate>
            @(string.Join(", ", ((Item)context).EnchantCategories))
        </DisplayTemplate>
    </DataGridColumn>
    <DataGridColumn TItem="Item" Field="@nameof(Item.RepairWith)" Caption="Réparable avec">
        <DisplayTemplate>
            @(string.Join(", ", ((Item)context).RepairWith))
        </DisplayTemplate>
    </DataGridColumn>
    <DataGridColumn TItem="Item" Field="@nameof(Item.CreatedDate)" Caption="Date de création" DisplayFormat="{0:d}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo("fr-FR")" />

    <DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Action">
        <DisplayTemplate>
            <a style="background-color: #FA8072; color: white; border-color: #FA8072; margin-bottom: 5px " href="Edit/@(context.Id)" class="btn btn-primary"><i class="fa fa-edit"></i><t style="background-color: #FA8072; color: white "> Editer</t></a>
            <button style="background-color: #FF0000; color: white; border-color: #FF0000 " type="button" class="btn btn-primary" @onclick="() => OnDelete(context.Id)"><i class="fa fa-trash"></i> Supprimer</button>
        </DisplayTemplate>
    </DataGridColumn>
</DataGrid>