@page "/management/pages"
@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">
    <MudPaper class="px-5 py-5">
        <MudStack>
            <MudStack Row="true">
                <MudStack class="mx-2 mb-5">
                    <MudText Typo="Typo.h4">تنظیمات برگه ها</MudText>
                    <MudText Typo="Typo.caption">برگه های وب سایت خود را ویرایش نمایید</MudText>
                </MudStack>

                <MudSpacer />
                @* <BaseButtonUi Size="Size.Large"
                              OnClickCallback="ViewModel.SubmitPagesSettingAsync"
                              class="mb-8 mt-2 w-64 rounded-md"
                              IsProcessing="@ViewModel.IsProcessing"
                              Icon="@Icons.Material.Outlined.Check"
                              Content="ثبتـــ اطلاعات" Variant="Variant.Filled" Color="Color.Success" /> *@
            </MudStack>
            <MudGrid class="!max-h-[80vh] overflow-auto">
                <MudItem xs="6">

                    <MudDivider />
                    <MudText class="mb-5 mt-4" Typo="Typo.h6">افزودن برگه جدید</MudText>

                    <MudTextField @bind-Value="@ViewModel.NewPageDto.Title" T="string" Label="عنوان" Variant="Variant.Outlined" />

                    <MudTextField class="my-3" @bind-Value="@ViewModel.NewPageDto.Slug" T="string" Label="اسلاگ" Variant="Variant.Outlined" />

                    <MudButton class="mt-1 w-full py-3" Variant="Variant.Outlined" Color="Color.Secondary" OnClick="ViewModel.AddPageAsync">افزودن +</MudButton>

                </MudItem>
                <MudItem xs="6">
                    <MudExpansionPanels>
                        @foreach (var navMenuItem in ViewModel.PageDto)
                        {
                            <MudExpansionPanel>
                                <TitleContent>
                                    <MudStack Row="true">
                                        <MudText class="my-auto">@navMenuItem.Title</MudText>
                                        <MudSpacer />
                                        <MudIconButton Icon="@Icons.Material.Filled.Edit"
                                                       OnClick="async ()=>{await ViewModel.EditPageAsync(navMenuItem);}"
                                                       Color="Color.Info"></MudIconButton>

                                        <MudIconButton Icon="@Icons.Material.Filled.Delete" OnClick="async ()=>{await ViewModel.RemovePageAsync(navMenuItem.Id);}" Color="Color.Error"></MudIconButton>
                                    </MudStack>
                                </TitleContent>
                                <ChildContent>

                                    <MudTextField class="my-3" @bind-Value="@navMenuItem.Title" T="string" Label="عنوان" Variant="Variant.Outlined" />
                                    <MudTextField class="my-3" @bind-Value="@navMenuItem.Slug" T="string" Label="اسلاگ" Variant="Variant.Outlined" />


                                </ChildContent>
                            </MudExpansionPanel>
                        }
                    </MudExpansionPanels>
                </MudItem>
            </MudGrid>
        </MudStack>
    </MudPaper>
</MudStack>

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