@using static Insight.Domain.Network.Agent.Messages.Update;
@inherits ComponentBase

<TableContainer T="HostUpdateEntity"
                @ref="Container"
                @bind-Search="Search"
                Title="@Title"
                Breadcrumbs="@Breadcrumbs"
                Data="LoadDataAsync">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Name" T="HostUpdateEntity">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Result" T="HostUpdateEntity">
                Result
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Date" T="HostUpdateEntity">
                Date
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Name">
            <MudLink OnClick="()=>OnDescription(context)">@context?.Name</MudLink>
        </MudTd>
        <MudTd DataLabel="Result">
            @if (Enum.TryParse<OsUpdateResultCodeEnum>(context?.Result, true, out var res))
            {
                var color = res switch
                {
                    OsUpdateResultCodeEnum.NotStarted => Color.Warning,
                    OsUpdateResultCodeEnum.InProgress => Color.Warning,
                    OsUpdateResultCodeEnum.Succeeded => Color.Success,
                    OsUpdateResultCodeEnum.SucceededWithErrors => Color.Warning,
                    OsUpdateResultCodeEnum.Failed => Color.Error,
                    OsUpdateResultCodeEnum.Aborted => Color.Error,
                    _ => Color.Warning
                };
                <MudText Color="color" Typo="Typo.inherit">@context?.Result?.ToString()</MudText>
            }
        </MudTd>
        <MudTd DataLabel="Date">
            @context?.Date?.ToLocalTime()
        </MudTd>
    </RowTemplate>
</TableContainer>

<CascadingValue Name="Model" Value="@Selected">
    <DetailsDialog @ref="_detailsDialog" />
</CascadingValue>

@code {
    private DetailsDialog? _detailsDialog;
}