@using Insight.Web.Pages.Management.Hosts;
@inherits ComponentBase

<TableContainer T="HostEntity" 
    @ref="Container" 
    @bind-Search="Search" 
    Title="@Title" 
    Breadcrumbs="@Breadcrumbs" 
    Data="LoadDataAsync"
    OnAdd="()=>_createDialog?.ToggleAsync()">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Name" T="HostEntity">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Customer" T="HostEntity">
                Customer
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            Description
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Name">
            <MudLink Href="@Navigation.Management.Hosts.DetailsHref(context?.Id.ToString())" Color="Color.Primary" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Name
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Customer">
            @if (context?.Customers is not null && context.Customers.Any())
            {
                <MudLink Href="@Navigation.Management.Customers.DetailsHref(context?.Customer.ToString())" Color="Color.Primary" Typo="Typo.inherit" Underline="Underline.None">
                    @context?.Customers?.FirstOrDefault()?.Name
                </MudLink>
            }
        </MudTd>
        <MudTd DataLabel="Description">
            @context?.Description
        </MudTd>
    </RowTemplate>
    <ActionTemplate>
        <MudMenuItem OnClick="@(()=>OnAssignAsync(context))">
            Assign
        </MudMenuItem>
    </ActionTemplate>
</TableContainer>

<HostCreateDialog @ref="_createDialog" OnChanges="OnRefreshAsync" />

@code {
    private HostCreateDialog? _createDialog;
}