@attribute [Route(RouteConstance.Package)]

@using CMSMicroservice.Protobuf.Protos.Package
@using BackOffice.Pages.Package.Components
@using BackOffice.Common.BaseComponents
@using DataModel = CMSMicroservice.Protobuf.Protos.Package.GetAllPackageByFilterResponseModel

<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="عنوان" CellStyle="text-wrap: nowrap;" HeaderStyle="text-wrap: nowrap;">
                    <CellTemplate>
                        <MudStack Row="true" AlignItems="AlignItems.Center">
                            <Image Src="@context.Item.ImagePath" Width="25" Height="25" ObjectPosition="ObjectPosition.Center" ObjectFit="ObjectFit.Fill" />
                            @if (string.IsNullOrWhiteSpace(context.Item.Title))
                            {
                                <MudText Typo="Typo.inherit">-</MudText>
                            }
                            else
                            {

                                <MudTooltip Text="@(context.Item.Title)" Arrow="true" Style="@($"{(context.Item.Title.Length < 70 ? string.Empty : "width:600px;")}")">
                                    <MudText Typo="Typo.inherit" Style="text-wrap: nowrap;">
                                        @(context.Item.Title.Truncate(20, true))
                                    </MudText>
                                </MudTooltip>
                            }
                        </MudStack>

                    </CellTemplate>
                </PropertyColumn>
                <PropertyColumn Property="x => x.Description" Title="توضیحات" CellStyle="text-wrap: nowrap;" HeaderStyle="text-wrap: nowrap;">
                    <CellTemplate>
                        @if (string.IsNullOrWhiteSpace(context.Item.Description))
                        {
                            <MudText Typo="Typo.inherit">-</MudText>
                        }
                        else
                        {

                            <MudTooltip Text="@(context.Item.Description.HtmlToText())" Arrow="true" Style="@($"{(context.Item.Description.Length < 70 ? string.Empty : "width:600px;")}")">
                                <MudText Typo="Typo.inherit" Style="text-wrap: nowrap;">
                                    @(context.Item.Description.HtmlToText().Truncate(20, true))
                                </MudText>
                            </MudTooltip>
                        }
                    </CellTemplate>
                </PropertyColumn>

                <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>
                        </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>






