@inherits ComponentBase

<TableContainer T="ViewModel"
    @ref="_container" 
    @bind-Search="_search" 
    Title="@_title" 
    Breadcrumbs="@_breadcrumbs"
    Data="LoadDataAsync"
    OnAdd="()=>_createDialog?.ToggleAsync()">
    <Header>
        <MudTh>
            <MudTableSortLabel SortLabel="Name" T="ViewModel">
                Name
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Tasks" T="ViewModel">
                Tasks
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Triggers" T="ViewModel">
                Triggers
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Executed" T="ViewModel">
                Executed
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="State" T="ViewModel">
                State
            </MudTableSortLabel>
        </MudTh>
        <MudTh>
            <MudTableSortLabel SortLabel="Status" T="ViewModel">
                Status
            </MudTableSortLabel>
        </MudTh>
    </Header>
    <RowTemplate>
        <MudTd DataLabel="Name">
            <MudLink Href="@Navigation.Management.Scheduler.Jobs.DetailsHref(context?.Id)" Typo="Typo.inherit" Underline="Underline.None">
                @context?.Name
            </MudLink>
        </MudTd>
        <MudTd DataLabel="Tasks">
            @{
                <MudLink Href="@Navigation.Management.Scheduler.Jobs.TasksHref(context.Id)" Typo="Typo.inherit" Underline="Underline.None">
                    @(context.Tasks?.ToString() ?? "0")
                </MudLink>
            }
        </MudTd>
        <MudTd DataLabel="Triggers">
            @{
                <MudLink Href="@Navigation.Management.Scheduler.Jobs.TriggersHref(context.Id)" Typo="Typo.inherit" Underline="Underline.None">
                    @(context.Triggers?.ToString() ?? "0")
                </MudLink>
            }
        </MudTd>
        <MudTd DataLabel="Executed">
            @context?.Executed.ToLocalTime()
        </MudTd>
        <MudTd DataLabel="State">
            @context.State
        </MudTd>
         <MudTd DataLabel="Status">
             <MudText Color="(context.Disabled ? Color.Error : Color.Success)" Typo="Typo.inherit">
                 @(context.Disabled ? "Disabled" : "Enabled")
             </MudText>
         </MudTd>
    </RowTemplate>
    <ActionTemplate>
        <MudMenuItem OnClick="@(()=>_editDialog?.ToggleAsync(context.Id))">
            Edit
        </MudMenuItem>
        <MudMenuItem OnClick="@(()=>_deleteDialog?.ToggleAsync(context.Id))">
            Delete
        </MudMenuItem>
    </ActionTemplate>
</TableContainer>

<JobCreateDialog @ref="_createDialog" OnChanges="OnRefreshAsync" />
<JobEditDialog @ref="_editDialog" OnChanges="OnRefreshAsync" />
<JobDeleteDialog @ref="_deleteDialog" OnChanges="OnRefreshAsync" />

@code{
    private JobCreateDialog? _createDialog;
    private JobEditDialog? _editDialog;
    private JobDeleteDialog? _deleteDialog;
}