@using static Insight.Agent.Messages.StoragePool;
@inherits ComponentBase

<BaseContainer Title="@Title" Breadcrumbs="@Breadcrumbs" LoadData="LoadDataAsync">
    <Content>
        @if (HostStoragePool is not null)
        {
            <MudGrid>
                <MudItem xs="12" sm="6" md="6" lg="3">
                    <KeyValueCard T="string" Key="Name" Value="@HostStoragePool?.Name" />
                </MudItem>
                <MudItem xs="12" sm="6" md="6" lg="3">
                    @{
                        var color = Enum.Parse<HealthState>(HostStoragePool?.Health, true) switch
                        {
                            HealthState.Healthy => Color.Success,
                            HealthState.Warning => Color.Warning,
                            HealthState.Unhealthy => Color.Error,
                            HealthState.Unknown => Color.Inherit,
                            _ => Color.Error
                        };

                        <KeyValueCard T="string" Key="Health" Value="@HostStoragePool?.Health" ValueColor="color" />
                    }
                </MudItem>
                @if (HostStoragePool?.States != null)
                {
                    var value = string.Join(", ", HostStoragePool.States);
                    var color = value switch
                    {
                        "Degraded" => Color.Error,
                        _ => Color.Success
                    };

                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Status" Value="value" ValueColor="color" />
                    </MudItem>
                }
                @if (HostStoragePool?.Primordial is false)
                {
                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="string" Key="Resiliency" Value="@HostStoragePool?.Resiliency" />
                    </MudItem>
                }
                <MudItem xs="12" sm="6" md="6" lg="3">
                    @{
                        var value = "-";

                        if (HostStoragePool?.Size != null)
                        {
                            value = $"{Math.Round((HostStoragePool.Size.Value / Math.Pow(1024, 3)), 2)} GB";
                        }

                        <KeyValueCard T="string" Key="Size" Value="@value" />
                    }
                </MudItem>
                <MudItem xs="12" sm="6" md="6" lg="3">
                    @{
                        var value = "-";

                        if (HostStoragePool?.AllocatedSize != null)
                        {
                            value = $"{Math.Round((HostStoragePool.AllocatedSize.Value / Math.Pow(1024, 3)), 2)} GB";
                        }

                        <KeyValueCard T="string" Key="Allocated" Value="@value" />
                    }
                </MudItem>
                @if (HostStoragePool?.Primordial is false)
                {
                    <MudItem xs="12" md="6" lg="3">
                        <KeyValueCard T="ulong?" Key="Sector Size" Value="@HostStoragePool?.SectorSize" />
                    </MudItem>
                }
                <MudItem xs="12" sm="6" md="6" lg="3">
                    <KeyValueCard T="long?" Href="@Navigation.Management.Hosts.Systems.StoragePools.PhysicalDisks.IndexHref(HostId, StoragePoolId)" Key="Physical Disks" Value="@(HostStoragePool?.PhysicalDisks?.Count() ?? 0)" KeyColor="Color.Primary" Icon="@Icons.Material.Outlined.Assignment" IconColor="@Color.Primary" />
                </MudItem>
                @if (HostStoragePool?.Primordial is false)
                {
                    <MudItem xs="12" sm="6" md="6" lg="3">
                        <KeyValueCard T="long?" Href="@Navigation.Management.Hosts.Systems.StoragePools.VirtualDisks.IndexHref(HostId, StoragePoolId)" Key="Virtual Disks" Value="@(HostStoragePool?.VirtualDisks?.Count() ?? 0)" KeyColor="Color.Primary" Icon="@Icons.Material.Outlined.Assignment" IconColor="@Color.Primary" />
                    </MudItem>
                }
            </MudGrid>
        }
    </Content>
</BaseContainer>