@using MudBlazor.Internal
    <MudExpansionPanels Class="mb-4">
        <MudExpansionPanel Icon="@Icons.Material.Filled.FilterList"
                           Text="Filters"
                           Expanded="true">
            <MudGrid>
                <MudItem xs="12" sm="6" md="4">
                    <MudTextField @bind-Value="filterRequest.Search"
                                  Label="Search"
                                  Placeholder="Name, number..."
                                  Immediate="true"
                                  DebounceInterval="500"
                                  OnDebounceIntervalElapsed="SearchLayers"
                                  Clearable="true"/>

                </MudItem>

                <MudItem xs="12" sm="6" md="4">
                    <MudButton Variant="Variant.Outlined"
                               OnClick="ClearFilters"
                               StartIcon="Icons.Material.Filled.Clear">
                        Clear filters
                    </MudButton>
                </MudItem>
            </MudGrid>
        </MudExpansionPanel>
    </MudExpansionPanels>

    <MudDivider Class="my-4"></MudDivider>
    
    <MudTable Items="layers.Items"
              Dense="true"
              Hover="true"
              Loading="isLoading"
              LoadingProgressColor="Color.Info"
              OnRowClick="@((TableRowClickEventArgs<LayerDto> args) => OnRowClick(args.Item))"
              T="LayerDto"
              Style="cursor: pointer;">
        <HeaderContent>
            <MudTh>Name</MudTh>
            <MudTh>Type</MudTh>
        </HeaderContent>
        <RowTemplate>
            <MudTd DataLabel="Name">@context.Name</MudTd>
            <MudTd DataLabel="Type">@context.Type</MudTd>
        </RowTemplate>
        <NoRecordsContent>
            <MudText>No layers to display</MudText>
        </NoRecordsContent>
        <LoadingContent>
            Loading...
        </LoadingContent>
    </MudTable>

    @if (layers.TotalCount > 0)
    {
        <MudGrid Class="mt-4" AlignItems="Center.Center">
            <MudItem xs="12" sm="6">
                <MudText Typo="Typo.body2">
                    Results @((layers.Page - 1) * layers.PageSize + 1) - @Math.Min(layers.Page * layers.PageSize, layers.TotalCount)
                    of @layers.TotalCount
                </MudText>
            </MudItem>
            <MudItem xs="12" sm="6" Class="d-flex justify-end">
                <MudPagination Count="layers.TotalPages"
                               Selected="layers.Page"
                               SelectedChanged="OnPageChanged"
                               ShowFirstButton="true"
                               ShowLastButton="true"/>
            </MudItem>
        </MudGrid>
    }
