@using static Insight.Agent.Messages.StoragePool;
@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="Name" T="ViewModel">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Resiliency" T="ViewModel">
                Resiliency
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Size" T="ViewModel">
                Size
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="SizeAllocated" T="ViewModel">
                SizeAllocated
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="States" T="ViewModel">
                State
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Health" T="ViewModel">
                Health
            </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="Name">
            <MudLink Href="@Navigation.Management.Hosts.Systems.StoragePools.DetailsHref(@context?.Hosts?.Id, context?.Id?.ToString())" Typo="Typo.inherit" Underline="Underline.None">
                @{
                    var value = context?.Name;

                    if (string.IsNullOrWhiteSpace(value)) value = "N/A";

                    @value
                }
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Resiliency">
            @context?.Resiliency
        </MudTd>
        <MudTd DataLabel="Size">
            @if (context?.Size is not null)
            {
                @($"{Math.Round((context.Size.Value / Math.Pow(1024, 3)), 2)} GB")
            }
        </MudTd>
        <MudTd DataLabel="SizeAllocated">
            @if (context?.SizeAllocated is not null)
            {
                @($"{Math.Round((context.SizeAllocated.Value / Math.Pow(1024, 3)), 2)} GB")
            }
        </MudTd>
        <MudTd DataLabel="States">
            @string.Concat(@context?.States)
        </MudTd>
        <MudTd DataLabel="Health">
            @{
                var color = Enum.Parse<HealthState>(context?.Health, true) switch
                {
                    HealthState.Healthy => Color.Success,
                    HealthState.Warning => Color.Warning,
                    HealthState.Unhealthy => Color.Error,
                    HealthState.Unknown => Color.Inherit,
                    _ => Color.Error
                };
                    <MudText Color="color" Typo="Typo.inherit">
                        @context?.Health
                    </MudText>
            }
        </MudTd>
    </RowTemplate>
</TableContainer>