@inherits ComponentBase

<TableContainer T="ViewModel"
    @ref="Container" 
    @bind-Search="Search" 
    Title="@Title" 
    Breadcrumbs="@Breadcrumbs" 
    Data="LoadDataAsync" 
    OnFilter="()=>Filter = true" 
    Filtered="Filtered">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Serial" T="ViewModel">
                Serial
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Hostname" T="ViewModel">
                Hostname
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Version" T="ViewModel">
                Version
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Assigned" T="ViewModel">
                Assigned
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Online" T="ViewModel">
                Online
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Serial">
            <MudLink Href="@Navigation.Management.Agents.DetailsHref(context?.Id.ToString())" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Serial
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Hostname">
            @context?.Hostname
        </MudTd>
        <MudTd DataLabel="Version">
            @context?.Version
        </MudTd>
        <MudTd DataLabel="Assigned">
            <MudCheckBox Checked="@(context.Hosts is not null && context.Hosts.Any())" Disabled DisableRipple />
        </MudTd>
        <MudTd DataLabel="Online">
            <MudText Color="(context.Online ? Color.Success : Color.Error)" Typo="Typo.inherit">
                @(context.Online ? "Online" : "Offline")
            </MudText>
        </MudTd>
    </RowTemplate>
    <ActionTemplate>
        <MudMenuItem OnClick="@(()=>_deleteDialog?.ToggleAsync(context.Id))">
            Delete
        </MudMenuItem>
    </ActionTemplate>
</TableContainer>

<ActionDialog @bind-Visible="Filter">
    <Content>
        <MudSwitch @bind-Checked="FilterUnassignedHost" Color="Color.Primary">
            Unassigned
        </MudSwitch>
    </Content>
    <Actions>
        <MudButton OnClick="OnFilterReset">
            Reset
        </MudButton>
        <MudButton OnClick="() => Filter = false" Color="Color.Secondary">
            Done
        </MudButton>
    </Actions>
</ActionDialog>

<AgentDeleteDialog @ref="_deleteDialog" OnChanges="OnRefreshAsync" />

@code {
    private AgentDeleteDialog? _deleteDialog;
}