@* Merged into /blog *@
@attribute [Authorize(Roles = "Administrator")]

@using BackOffice.Services.Blog

@inject IBlogCategoryService BlogCategoryService

<div>
    <MudStack Spacing="2">
        <MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
            <MudText Typo="Typo.h5">مدیریت دسته‌بندی‌های بلاگ</MudText>
            <MudButton Variant="Variant.Filled"
                       Color="Color.Primary"
                       StartIcon="@Icons.Material.Filled.Add"
                       OnClick="CreateCategory">
                افزودن دسته‌بندی
            </MudButton>
        </MudStack>

        <MudDataGrid T="BlogCategoryItemDto"
                     @ref="_grid"
                     ServerData="LoadServerData"
                     Hover="true"
                     Elevation="1"
                     Dense="true"
                     Height="calc(100vh - 240px)">
            <Columns>
                <PropertyColumn Property="x => x.Id" Title="شناسه" />
                <PropertyColumn Property="x => x.Title" Title="عنوان" />
                <PropertyColumn Property="x => x.Slug" Title="اسلاگ" />
                <PropertyColumn Property="x => x.IconName" Title="آیکون" />
                <PropertyColumn Property="x => x.PostCount" Title="تعداد پست" />
                <PropertyColumn Property="x => x.IsActive" Title="وضعیت">
                    <CellTemplate>
                        <MudChip Color="@(context.Item.IsActive ? Color.Success : Color.Error)"
                                 Size="Size.Small">
                            @(context.Item.IsActive ? "فعال" : "غیرفعال")
                        </MudChip>
                    </CellTemplate>
                </PropertyColumn>
                <PropertyColumn Property="x => x.SortOrder" Title="ترتیب" />
                <TemplateColumn Title="عملیات" Sortable="false">
                    <CellTemplate>
                        <MudStack Row="true" Spacing="1">
                            <MudTooltip Text="ویرایش">
                                <MudIconButton Icon="@Icons.Material.Filled.Edit"
                                               Size="Size.Small"
                                               Color="Color.Primary"
                                               OnClick="@(() => EditCategory(context.Item))" />
                            </MudTooltip>
                            <MudTooltip Text="حذف">
                                <MudIconButton Icon="@Icons.Material.Filled.Delete"
                                               Size="Size.Small"
                                               Color="Color.Error"
                                               OnClick="@(() => DeleteCategory(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="BlogCategoryItemDto" PageSizeOptions="@(new int[] { 20, 50, 100 })"
                                  InfoFormat="سطر {first_item} تا {last_item} از {all_items}"
                                  RowsPerPageString="تعداد در صفحه" />
            </PagerContent>
        </MudDataGrid>
    </MudStack>
</div>
