@typeparam T

<PageTitle>@Title</PageTitle>

<div class="mt-7 mb-6 ml-4">
    <div class="d-flex mb-3">
        <div>
            <MudStack Row="true">
                <MudBreadcrumbs Items="Breadcrumbs" Style="padding: 0px;" />
                @if (OnAdd.HasDelegate)
                {
                    @if (AddBreadcrumbs is not null)
                    {
                        <MudBreadcrumbs Items="AddBreadcrumbs" Class="ml-n3" Style="padding: 0px;" />
                    }

                    <MudIconButton OnClick="OnAddClick" Icon="@Icons.Material.Filled.Add" Size="Size.Small" Color="Color.Primary" Class="ml-n4" />
                }
            </MudStack>
        </div>
        <div class="ml-auto">
            <MudTextField T="string" Value="@Search" ValueChanged="@(s=>SearchAsync(s))" DebounceInterval="250" Immediate Variant="Variant.Text" Clearable OnBlur="OnSearchReleased"
                          Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Small" Style="margin-top: -15px; width: 40vh;"/>
        </div>
    </div>
</div>

<MudTable T="T" @ref="Table" ServerData="OnLoadDataAsync" RowsPerPage="50" Loading="Loading" Elevation="0" Dense Square FixedHeader="true" FixedFooter="true" Height="calc(100vh - 205px)">
    <HeaderContent>
        @if (Header is not null)
        {
            @Header
        }
        <MudTh Style="text-align: right; width: 100px;">
            <MudStack Row="true" Class="mr-6">
                <MudButton OnClick="OnFilterClick" Variant="Variant.Text" Size="Size.Small" Color="@(Filtered ? Color.Warning : Color.Inherit)" DisableElevation Disabled="@(!OnFilter.HasDelegate)">
                    Filter
                </MudButton>
                <MudButton OnClick="RefreshAsync" Variant="Variant.Text" Size="Size.Small" DisableElevation Disabled="@(DisableRefresh || Loading)">
                    Refresh
                </MudButton>
            </MudStack>
        </MudTh>
    </HeaderContent>
    <RowTemplate>
        @if (RowTemplate is not null)
        {
            @RowTemplate(context)
        }
        <MudTd DataLabel="Actions" Style="text-align: right;">
            @if (ActionTemplate is not null)
            {
                <MudMenu Label="Actions" Variant="Variant.Text" Size="Size.Small" Dense="true" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" IconColor="Color.Primary"
                     ActivationEvent="@MouseEvent.MouseOver" AnchorOrigin="Origin.BottomRight" FullWidth="true" Disabled="@(DisableAction)">
                    @if (ActionTemplate is not null)
                    {
                        @ActionTemplate(context)
                    }
                </MudMenu>
            }
        </MudTd>
    </RowTemplate>
    <PagerContent>
        <MudTablePager RowsPerPageString="" />
    </PagerContent>
</MudTable>