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

<MudDialog DisableSidePadding="true" class="mx-auto">
    <DialogContent>
        <MudContainer class="max-h-[30rem]" Style="overflow-y: scroll">
            <MudStack>
                <MudDivider class="-mt-3" />
                <MudStack Spacing="0">

                    <MudText Typo="Typo.h6"><b>اطلاعات کلی</b></MudText>
                    <MudText Typo="Typo.caption">اطلاعات کلی دسته بندی را به دقت وارد کنید</MudText>
                </MudStack>
                <MudGrid>
                    <MudItem sm="12" md="6">
                        <MudTextField T="string" Label="نام فارسی نفش" @bind-Value="@ViewModel.PageDto.PersianName" Variant="Variant.Outlined"></MudTextField>
                    </MudItem>
                    <MudItem sm="12" md="6">
                        <MudTextField T="string" Label="نام انگلیسی نقش" @bind-Value="@ViewModel.PageDto.EnglishName" Variant="Variant.Outlined"></MudTextField>
                    </MudItem>

                    <MudItem sm="12">
                        <MudTextField T="string" Label="توضیحاتــــ" @bind-Value="@ViewModel.PageDto.Description" Variant="Variant.Outlined"></MudTextField>
                    </MudItem>

                    <MudItem sm="12">
                        <MudStack Spacing="0">

                            <MudText Typo="Typo.h6"><b>سطح دسترسی ها</b></MudText>
                            <MudText Typo="Typo.caption">اطلاعات کلی دسته بندی را به دقت وارد کنید</MudText>
                        </MudStack>
                    </MudItem>
                
                    @foreach (var item in ViewModel.RoleClaims)
                    {
                    
                        <MudItem sm="6" md="4">
                            <MudStack Spacing="0">
                                <MudSwitch @bind-Value="@item.IsSelected" Label="@item.Title" Color="Color.Info" />
                            </MudStack>
                        </MudItem>
                    }

                </MudGrid>
            </MudStack>
        </MudContainer>
    </DialogContent>
    <DialogActions>
        <MudStack Row="true" class="w-full mx-4 mb-2">

            @if (ViewModel.IsEditing)
            {
                <BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
                              Icon="@Icons.Material.Outlined.Check"
                              Variant="Variant.Filled" Color="Color.Success"
                              Content="ثبت ویرایش" OnClickCallback="@ViewModel.SubmitEditAsync" />
            }
            else
            {
                <BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
                              Icon="@Icons.Material.Outlined.Check"
                              Variant="Variant.Filled" Color="Color.Success"
                              Content="تایید" OnClickCallback="@ViewModel.SubmitCreateAsync" />
            }
            <MudSpacer />
            <MudButton Variant="Variant.Outlined" Size="Size.Large" Color="Color.Error" OnClick="@ViewModel.Cancel">بستن</MudButton>
        </MudStack>
    </DialogActions>
</MudDialog>
@code {

    [CascadingParameter]
    MudDialogInstance MudDialog { get; set; }

    [Parameter]
    public ApplicationRole? Role { get; set; }

    public RoleActionDialogBoxViewModel ViewModel { get; set; }

    protected override async Task OnInitializedAsync()
    {
        if (Role == null)
            ViewModel = new RoleActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog);
        else
            ViewModel = new RoleActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog, Role);
        await ViewModel.InitializeAsync();
        await base.OnInitializedAsync();
    }
}
