@page "/setting/faq"

@attribute [Microsoft.AspNetCore.Authorization.Authorize]

@inject IDialogService DialogService
@inject NavigationManager NavigationManager
@inject ISnackbar Snackbar
@inject IUserUtility UserUtility
@inject IRestWrapper RestWrapper

<MudStack class="h-full w-full p-8">
    <MudGrid>
        <MudItem xs="12">
            <MudStack Row="true" class="mb-5">
                <MudText Typo="Typo.h4">سوالات متداول</MudText>
                <MudSpacer />
                <MudButton Variant="Variant.Filled"
                           DisableElevation="true"
                           StartIcon="@Icons.Material.Outlined.Add"
                           Color="Color.Secondary"
                           OnClick="@ViewModel.AddClicked"
                           class="my-auto">افزودن سوالات متداول جدید</MudButton>
            </MudStack>
            <MudPaper>
                <MudDataGrid FixedFooter="true" FixedHeader="true" Striped="true"
                             T="BaseFaq" Items="@ViewModel.PageDto" Filterable="false"
                             CurrentPage="@ViewModel.CurrentPage"
                             RowsPerPage="20"
                             Loading="@ViewModel.IsProcessing"
                             SortMode="@SortMode.None" Groupable="false">
                    <Columns>
                        <PropertyColumn Title="عنوان" Property="arg => arg.Title" />
                        <PropertyColumn Title="اسلاگ" Property="arg => arg.Slug" />
                        <TemplateColumn CellClass="d-flex justify-end">
                            <CellTemplate>
                                <MudStack Row="true">

                                    <MudIconButton Icon="@Icons.Material.Filled.Edit"
                                                   Size="@Size.Small"
                                                   Variant="@Variant.Outlined"
                                                   Color="@Color.Info"
                                                   OnClick="async()=>await ViewModel.EditClicked(context.Item)" />
                                    <MudIconButton Icon="@Icons.Material.Filled.Delete"
                                                   Size="@Size.Small"
                                                   Variant="@Variant.Outlined"
                                                   OnClick="async () => await ViewModel.DeleteAsync(context.Item.Id)"
                                                   Color="@Color.Error" />
                                </MudStack>
                            </CellTemplate>
                        </TemplateColumn>
                    </Columns>
                    <PagerContent>
                        <MudStack Row="true" class="w-full">

                            <MudPagination Rectangular="true" Variant="Variant.Filled" Count="@ViewModel.PageCount"
                                           SelectedChanged="@ViewModel.ChangePageAsync" class="mx-auto my-4" />
                        </MudStack>

                    </PagerContent>
                </MudDataGrid>
            </MudPaper>
        </MudItem>
    </MudGrid>
</MudStack>

@code
{
    public FaqManagementPageViewModel ViewModel { get; set; }
    protected override async Task OnInitializedAsync()
    {
        ViewModel = new FaqManagementPageViewModel(DialogService, NavigationManager, RestWrapper, Snackbar, UserUtility);
        await ViewModel.InitializeAsync();
        await base.OnInitializedAsync();
    }
}
