@using static Insight.Domain.Messages.Agent.VirtualDisk;
@inherits ComponentBase

<TableContainer T="HostStoragePoolVirtualDiskEntity"
                @ref="Container"
                @bind-Search="Search"
                Title="@Title"
                Breadcrumbs="@Breadcrumbs"
                Data="LoadDataAsync">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Name" T="HostStoragePoolVirtualDiskEntity">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Provisioning" T="HostStoragePoolVirtualDiskEntity">
                Provisioning
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Resiliency" T="HostStoragePoolVirtualDiskEntity">
                Resiliency
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Size" T="HostStoragePoolVirtualDiskEntity">
                Size
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Allocated" T="HostStoragePoolVirtualDiskEntity">
                Allocated
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Footprint" T="HostStoragePoolVirtualDiskEntity">
                Footprint
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="ReadCache" T="HostStoragePoolVirtualDiskEntity">
                Read Cache
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="WriteCache" T="HostStoragePoolVirtualDiskEntity">
                Write Cache
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Redundancy" T="HostStoragePoolVirtualDiskEntity">
                Redundancy
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="HealthStatus" T="HostStoragePoolVirtualDiskEntity">
                Health
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Name">
            <MudLink Href="@Navigation.Management.Hosts.Systems.StoragePools.VirtualDisks.DetailsHref(HostId, StoragePoolId, context?.Id.ToString())" Typo="Typo.inherit" Underline="Underline.None">
                @(context?.Name ?? "Unnamed")
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Provisioning">
            @context?.Provisioning
        </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="Allocated">
            @if (context?.AllocatedSize is not null)
                @($"{Math.Round((context.AllocatedSize.Value / Math.Pow(1024, 3)), 2)} GB")
        </MudTd>
        <MudTd DataLabel="Footprint">
            @if (context?.Footprint is not null)
                @($"{Math.Round((context.Footprint.Value / Math.Pow(1024, 3)), 2)} GB")
        </MudTd>
        <MudTd DataLabel="ReadCache">
            @if (context?.ReadCacheSize is not null)
                @($"{Math.Round((context.ReadCacheSize.Value / Math.Pow(1024, 3)), 2)} GB")
        </MudTd>
        <MudTd DataLabel="WriteCache">
            @if (context?.WriteCacheSize is not null)
                @($"{Math.Round((context.WriteCacheSize.Value / Math.Pow(1024, 3)), 2)} GB")
        </MudTd>
        <MudTd DataLabel="Redundancy">
            @context?.PhysicalRedundancy
        </MudTd>
        <MudTd DataLabel="HealthStatus">
            @{
                var color = Enum.Parse<HealthState>(context?.Health ?? HealthState.Unknown.ToString(), true) switch
                {
                    HealthState.Healthy => Color.Success,
                    HealthState.Warning => Color.Warning,
                    HealthState.Unhealthy => Color.Error,
                    HealthState.Unknown => Color.Inherit,
                    _ => Color.Inherit
                };
                <MudText Color="color">
                    @context?.Health
                </MudText>
            }
        </MudTd>
    </RowTemplate>
</TableContainer>