@inherits ComponentBase

<TableContainer T="HostEntity" 
    @ref="Container" 
    @bind-Search="Search" 
    Title="@Title" 
    Breadcrumbs="@Breadcrumbs" 
    Data="LoadDataAsync">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Name" T="HostEntity">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Description" T="HostEntity">
                Description
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Agent" T="HostEntity">
                Agent
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Name">
            <MudLink Href="@Navigation.Management.Hosts.DetailsHref(context.Id.ToString())" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Name
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Description">
            @context?.Description
        </MudTd>
        <MudTd DataLabel="Agent">
            @{
                if (string.IsNullOrWhiteSpace(context.Agent) is false && context.Agents is not null && context.Agents.Any())
                {
                    <MudLink Href="@Navigation.Management.Agents.DetailsHref(context.Agents.First().Id.ToString())" Typo="Typo.inherit" Underline="Underline.None">
                        @context?.Agents.First()?.Serial
                    </MudLink>
                }
                else
                {
                    @context?.Agent
                }
            }
        </MudTd>
    </RowTemplate>
    <ActionTemplate>
        <MudMenuItem OnClick="@(()=>OnAssign(context))">
            Assign
        </MudMenuItem>
    </ActionTemplate>
</TableContainer>

<ActionDialog @bind-Visible="Assign">
    <Content>
        <MudTextField T="string" @bind-Value="Model.Name" Label="Name" Variant="Variant.Text" Margin="Margin.Dense" ReadOnly />
        <MudTextField T="string" @bind-Value="Model.Description" Label="Description" Variant="Variant.Text" Margin="Margin.Dense" ReadOnly />
    </Content>
    <Actions>
        <MudButton OnClick="()=>Assign = false">
            Cancel
        </MudButton>
        <MudButton OnClick="OnAddSubmitAsync" Color="Color.Secondary">
            Assign
        </MudButton>
    </Actions>
</ActionDialog>