@inherits ComponentBase

<TableContainer T="ViewModel"
    @ref="Container" 
    @bind-Search="Search" 
    Title="@Title" 
    Breadcrumbs="@Breadcrumbs" 
    Data="LoadDataAsync"
    OnAdd="()=>_createDialog?.ToggleAsync()"
    OnFilter="()=>Filter = true"
    Filtered="Filtered">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Customer" T="ViewModel">
                Customer
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Name" T="ViewModel">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Agent" T="ViewModel">
                Agent
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Online" T="ViewModel">
                Online
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Customer">
            <MudLink Href="@Navigation.Management.Customers.DetailsHref(context.Customer?.Id)" Typo="Typo.inherit" Underline="Underline.None">
                @context.Customer?.Name
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Name">
            <MudLink Href="@Navigation.Management.Hosts.DetailsHref(context.Id.ToString())" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Name
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Agent">
            <MudLink Href="@Navigation.Management.Agents.DetailsHref(context?.Agent?.Id?.ToString())" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Agent?.Serial
            </MudLink>
        </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="@(()=>_editDialog?.ToggleAsync(context?.Id?.ToString()))">
            Edit
        </MudMenuItem>
        <MudMenuItem OnClick="@(()=>_deleteDialog?.ToggleAsync(context?.Id?.ToString()))">
            Delete
        </MudMenuItem>
    </ActionTemplate>
</TableContainer>

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

<HostCreateDialog @ref="_createDialog" OnChanges="OnRefreshAsync" />
<HostEditDialog @ref="_editDialog" OnChanges="OnRefreshAsync" />
<HostDeleteDialog @ref="_deleteDialog" OnChanges="OnRefreshAsync" />

@code {
    private HostCreateDialog? _createDialog;
    private HostEditDialog? _editDialog;
    private HostDeleteDialog? _deleteDialog;
}