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

<TableContainer T="ViewModel"
                @ref="Container"
                @bind-Search="Search"
                Title="@Title"
                Breadcrumbs="@Breadcrumbs"
                Data="LoadDataAsync">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Customer" T="ViewModel">
                Customer
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Host" T="ViewModel">
                Host
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Pending" T="ViewModel">
                Pending
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Result" T="ViewModel">
                Result
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Customer">
            <MudLink Href="@Navigation.Management.Customers.DetailsHref(@context?.Customers?.Id)" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Customers?.Name
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Host">
            <MudLink Href="@Navigation.Management.Hosts.DetailsHref(@context?.Hosts?.Id)" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Hosts?.Name
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Pending">
            <MudCheckBox Checked="@context?.Pending" Disabled DisableRipple />
        </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>
    </RowTemplate>
</TableContainer>