@using static Insight.Domain.Network.Agent.Messages.VirtualMaschine;
@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="Configuration" T="ViewModel">
                Configuration
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="GuestOs" T="ViewModel">
                Operation System
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Snapshots" T="ViewModel">
                Snapshots
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Enabled" 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.VirtualMaschines.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="Configuration">
            @context?.Configuration
        </MudTd>
        <MudTd DataLabel="GuestOs">
            @context?.GuestOs
        </MudTd>
        <MudTd DataLabel="Snapshots">
            @(context?.Snapshots ?? 0)
        </MudTd>
        <MudTd DataLabel="Enabled">
            @{
                var color = Enum.Parse<EnabledEnum>(context?.Enabled, true) switch
                {
                    EnabledEnum.Aktiviert => Color.Success,
                    EnabledEnum.Deaktiviert => Color.Error,
                    _ => Color.Inherit
                };

                var text = Enum.Parse<EnabledEnum>(context?.Enabled, true) switch
                {
                    EnabledEnum.Aktiviert => "Running",
                    EnabledEnum.Deaktiviert => "Stopped",
                    _ => ""
                };

                <MudText Color="color" Typo="Typo.inherit">
                    @text
                </MudText>
            }
        </MudTd>
        <MudTd DataLabel="Health">
            @{
                var color = Enum.Parse<HealthStatusEnum>(context?.Health, true) switch
                {
                    HealthStatusEnum.OK => Color.Success,
                    HealthStatusEnum.Hauptfehler => Color.Warning,
                    HealthStatusEnum.Kritischer_Fehler => Color.Error,
                    _ => Color.Error
                };

                <MudText Color="color" Typo="Typo.inherit">
                    @context?.Health
                </MudText>
            }
        </MudTd>
    </RowTemplate>
</TableContainer>