@attribute [Route(RouteConstance.UserPage)]

@using CMSMicroservice.Protobuf.Protos.User
@using BackOffice.Pages.User.Components
@using BackOffice.Common.BaseComponents
@using DataModel = CMSMicroservice.Protobuf.Protos.User.GetAllUserByFilterResponseModel

<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.FirstName" Variant="Variant.Outlined" Margin="Margin.Dense" />
        </MudItem>
        <MudItem xs="12" sm="6" md="3">
            <MudTextField T="string" Clearable="true" Label="نام خانوادگی" @bind-Value="@_request.Filter.LastName" Variant="Variant.Outlined" Margin="Margin.Dense" />
        </MudItem>
        <MudItem xs="12" sm="6" md="3">
            <MudTextField T="string" Clearable="true" Label="موبایل" @bind-Value="@_request.Filter.Mobile" Variant="Variant.Outlined" Margin="Margin.Dense" />
        </MudItem>
        <MudItem xs="12" sm="6" md="3">
            <MudTextField T="string" Clearable="true" Label="کدملی" @bind-Value="@_request.Filter.NationalCode" 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 />
                <col style="width: 58px;" />
            </ColGroup>
            <ToolBarContent>
                <MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Style="width:100%">
                    <MudText>مدیریت کاربر</MudText>
                    <MudButton Variant="Variant.Outlined" Color="Color.Info" OnClick="ExportToExcel" StartIcon="@Icons.Material.Filled.FileDownload" Size="Size.Small">خروجی Excel</MudButton>
                </MudStack>
            </ToolBarContent>
            <Columns>
                <PropertyColumn Property="x => x.Id" Title="شناسه" />
                <PropertyColumn Property="x => x.Mobile" Title="موبایل" />
                <PropertyColumn Property="x => x.FirstName" Title="نام و نام خانوادگی" CellStyle="text-wrap: nowrap;" HeaderStyle="text-wrap: nowrap;">
                    <CellTemplate>
                        <MudText Typo="Typo.inherit">@($"{context.Item.FirstName} {context.Item.LastName}")</MudText>

                    </CellTemplate>
                </PropertyColumn>
                <PropertyColumn Property="x => x.NationalCode" Title="کدملی" />



                <TemplateColumn StickyLeft="true" Title="عملیات" CellStyle="text-wrap: nowrap;" HeaderStyle="text-wrap: nowrap;">
                    <CellTemplate>
                        <MudStack Row="true" AlignItems="AlignItems.Center">
                            <MudMenu Icon="@Icons.Material.Filled.MoreVert"
                                     AriaLabel="Open user menu">
                                <MudMenuItem OnClick="@(() => Navigation.NavigateTo($"{RouteConstance.UserOrder}{context.Item.Id}"))">سفارش‌ها</MudMenuItem>
                                <MudMenuItem OnClick="@(() => Navigation.NavigateTo($"{RouteConstance.UserAddress}{context.Item.Id}"))">آدرس ها</MudMenuItem>
                                <MudMenuItem OnClick="@(async () => await OnclickUserRoleDialog(context.Item.Id))">مدیریت نقش</MudMenuItem>
                                <MudMenuItem OnClick="() => OnDelete(context.Item)">آرشیو</MudMenuItem>
                            </MudMenu>
                        </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>


