@attribute [Route(RouteConstance.Role)]

@using CMSMicroservice.Protobuf.Protos.Role
@using BackOffice.Pages.Role.Components
@using BackOffice.Common.BaseComponents
@using DataModel = CMSMicroservice.Protobuf.Protos.Role.GetAllRoleByFilterResponseModel

<BackOffice.Common.BaseComponents.BasePageComponent @ref="_basePage" OnClearFilterClick="OnFilterCleared" OnSubmitClick="OnFilterSubmit">
    <Filters>
        <MudItem xs="12" sm="6" md="3">
            <MudTextField T="string" Clearable="true" Label="عنوان" @bind-Value="@_request.Filter.Title" Variant="Variant.Outlined" Margin="Margin.Dense" />
        </MudItem>
    </Filters>
    <Content>
        <MudDataGrid T="DataModel" ServerData="@(new Func<GridState<DataModel>, Task<GridData<DataModel>>>(ServerReload))"
                     Hover="true" @ref="_gridData" Height="calc(100vh - 240px)">
            <ColGroup>
                <col />
                <col />
                <col />
                <col style="width: 58px;" />
            </ColGroup>
            <ToolBarContent>
                <MudText>مدیریت نقش</MudText>
                <MudSpacer />
                <MudStack Spacing="2" Row="true" Justify="Justify.Center" AlignItems="AlignItems.Center">
                    <MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" ButtonType="ButtonType.Button" OnClick="CreateNew">افزودن</MudButton>
                </MudStack>
            </ToolBarContent>
            <Columns>
                <PropertyColumn Property="x => x.Id" Title="شناسه" />
                <PropertyColumn Property="x => x.Title" Title="عنوان" />
                <PropertyColumn Property="x => x.Name" Title="عنوان لاتین" />


                <TemplateColumn StickyLeft="true" Title="عملیات" CellStyle="text-wrap: nowrap;" HeaderStyle="text-wrap: nowrap;">
                    <CellTemplate>
                        <MudStack Row="true" AlignItems="AlignItems.Center">
                            <MudTooltip Text="ویرایش">
                                <MudIconButton Icon="@Icons.Material.Filled.EditNote" Size="Size.Small" ButtonType="ButtonType.Button" OnClick="@(() => Update(context.Item.Adapt<DataModel>()))" />
                            </MudTooltip>

                            <MudTooltip Text="آرشیو">
                                <MudIconButton Icon="@Icons.Material.Filled.DeleteOutline" Size="Size.Small" ButtonType="ButtonType.Button" OnClick="@(() => OnDelete(context.Item))" />
                            </MudTooltip>

                            <MudTooltip Text="ویرایش دسترسی‌ها">
                                <MudIconButton Icon="@Icons.Material.Filled.Security"
                                               Size="Size.Small"
                                               Color="Color.Primary"
                                               ButtonType="ButtonType.Button"
                                               OnClick="@(() => EditPermissions(context.Item))"
                                               />
                            </MudTooltip>
                        </MudStack>
                    </CellTemplate>
                </TemplateColumn>
            </Columns>
            <NoRecordsContent>
                <MudAlert Severity="Severity.Info" Dense="true" Variant="Variant.Text" Class="my-4">موردی یافت نشد.</MudAlert>
            </NoRecordsContent>
            <PagerContent>
                <MudDataGridPager T="DataModel" PageSizeOptions=@(new int[] { 20, 50, 100 }) InfoFormat="سطر {first_item} تا {last_item} از {all_items}" RowsPerPageString="تعداد در صفحه" />
            </PagerContent>
        </MudDataGrid>
    </Content>
</BackOffice.Common.BaseComponents.BasePageComponent>





