@inherits ComponentBase

<TableContainer T="CustomerEntity" 
    @ref="_container" 
    @bind-Search="_search" 
    Title="@_title" 
    Breadcrumbs="@_breadcrumbs"
    Data="LoadDataAsync" 
    OnAdd="()=>_createDialog?.ToggleAsync()">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Name" T="CustomerEntity">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Tag" T="CustomerEntity">
                Tag
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Hosts" T="CustomerEntity">
                Hosts
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Name">
                <MudLink Href="@Navigation.Management.Customers.DetailsHref(context?.Id)" Typo="Typo.inherit" Underline="Underline.None">
                    @context?.Name
                </MudLink>
            </MudTd>
            <MudTd DataLabel="Tag">
                @context?.Tag
            </MudTd>
            <MudTd DataLabel="Hosts">
                @{
                    var value = "0";

                    if (context.Hosts is not null && context.Hosts.Any())
                    {
                        value = @context.Hosts.Count.ToString();
                    }

                    <MudLink Href="@Navigation.Management.Customers.HostsHref(context.Id)" Typo="Typo.inherit" Underline="Underline.None">
                        @value
                    </MudLink>
                }
            </MudTd>
    </RowTemplate>
    <ActionTemplate>
        <MudMenuItem OnClick="@(()=>_editDialog?.ToggleAsync(context.Id))">
            Edit
        </MudMenuItem>
        <MudMenuItem OnClick="@(()=>_deleteDialog?.ToggleAsync(context.Id))">
            Delete
        </MudMenuItem>
    </ActionTemplate>
</TableContainer>

<CustomerCreateDialog @ref="_createDialog" OnChanges="OnRefreshAsync" />
<CustomerEditDialog @ref="_editDialog" OnChanges="OnRefreshAsync" />
<CustomerDeleteDialog @ref="_deleteDialog" OnChanges="OnRefreshAsync" />

@code{
    private CustomerCreateDialog? _createDialog;
    private CustomerEditDialog? _editDialog;
    private CustomerDeleteDialog? _deleteDialog;
}