@page "/trait-list"
@using DataLayer.Interfaces
@using Domain.XML_Model
@attribute [StreamRendering(true)]


<div>
    <h3>Trait</h3>
</div>
<div>
    @if (Traits == null)
    {
        <p><em>Loading...</em></p>
    }
    else
    {
        <table class="table table-striped">
            <thead>
            <tr>
                <th>Nom</th>
                <th>Effet</th>
                <th>Multiple</th>
                <th>Description</th>
            </tr>
            </thead>
            <tbody>
            @foreach (var trait in Traits)
            {
                <tr>
                    <td>@trait.Nom</td>
                    <td>@trait.Effet</td>
                    <td>@trait.Multiple</td>
                    <td>@trait.Description</td>
                </tr>
            }
            </tbody>
        </table>
    }
</div>

@code {
    [Inject]
    public IAbstractRepository<Trait> _traitRepository { get; set; }
    private List<Trait> Traits { get; set; }

    protected override async Task OnInitializedAsync()
    {
        // Load the traits data here
        Traits = await LoadTraitsAsync();
    }

    private async Task<List<Trait>> LoadTraitsAsync()
    {
        // Implement the logic to load traits data
        var traits = await _traitRepository.GetAll();
        return traits.OrderBy(t => t.Nom).ToList();
    }
}