@using BackOffice.Shared
@using Microsoft.AspNetCore.Components.Authorization
@inherits LayoutComponentBase
@attribute [AllowAnonymous]

<MudRTLProvider RightToLeft="true">
    <MudThemeProvider @ref="_themeProvider" Theme="CustomMudTheme.CustomMudBlazorTheme" IsDarkMode="_isDarkMode" />
    <MudDialogProvider />
    <MudSnackbarProvider />
    <MudPopoverProvider />
    <MudLayout>
        <MudAppBar Elevation="1" Color="Color.Surface">
            <MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
            <MudText Class="mx-2" Typo="Typo.h6">کارا بازار سلامت</MudText>
            <MudSpacer />
            <AuthorizeView>
                <Authorized>
                    <GlobalSearch />
                </Authorized>
            </AuthorizeView>
            <MudSpacer />
            <MudMenu AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter" Dense="true"
                      ActivationEvent="@MouseEvent.LeftClick" Class="mx-1">
                <ActivatorContent>
                    <MudBadge Color="Color.Error" Dot="true" Overlap="true" Visible="false">
                        <MudIconButton Icon="@Icons.Material.Filled.Notifications" Color="Color.Inherit" />
                    </MudBadge>
                </ActivatorContent>
                <ChildContent>
                    <MudPaper Class="pa-4" MinWidth="280px">
                        <MudText Typo="Typo.subtitle2" Class="mb-2">اعلان‌ها</MudText>
                        <MudDivider Class="mb-2" />
                        <MudStack AlignItems="AlignItems.Center" Justify="Justify.Center" Class="py-4">
                            <MudIcon Icon="@Icons.Material.Filled.NotificationsNone" Color="Color.Secondary" Size="Size.Large" />
                            <MudText Typo="Typo.body2" Color="Color.Secondary">اعلان جدیدی وجود ندارد</MudText>
                        </MudStack>
                    </MudPaper>
                </ChildContent>
            </MudMenu>
            <MudIconButton Icon="@(_isDarkMode ? Icons.Material.Filled.LightMode : Icons.Material.Filled.DarkMode)"
                           Color="Color.Inherit"
                           OnClick="ToggleDarkMode"
                           Title="@(_isDarkMode ? "حالت روشن" : "حالت تاریک")" />
            <AuthorizeView>
                <Authorized>
                    <MudMenu AnchorOrigin="Origin.BottomLeft" TransformOrigin="Origin.TopLeft" Dense="true">
                        <ActivatorContent>
                            <MudStack Row AlignItems="AlignItems.Center" Class="mx-2 cursor-pointer">
                                <MudAvatar Color="Color.Primary" Size="Size.Small">
                                    <MudIcon Icon="@Icons.Material.Filled.Person" />
                                </MudAvatar>
                                <MudText Typo="Typo.body2" Class="d-none d-sm-flex">@(context.User.Claims?.FirstOrDefault(x => x.Type == "sub")?.Value)</MudText>
                            </MudStack>
                        </ActivatorContent>
                        <ChildContent>
                            <MudMenuItem Href="/settings" Icon="@Icons.Material.Filled.Settings">تنظیمات</MudMenuItem>
                            <MudDivider />
                            <MudMenuItem OnClick="Signout" Icon="@Icons.Material.Filled.Logout" IconColor="Color.Error">خروج از حساب</MudMenuItem>
                        </ChildContent>
                    </MudMenu>
                </Authorized>
            </AuthorizeView>
        </MudAppBar>
        <MudDrawer @bind-Open="@_drawerOpen" Breakpoint="Breakpoint.Lg" Elevation="1"
                   Variant="@DrawerVariant.Responsive" ClipMode="DrawerClipMode.Always">
            <NavMenu />
        </MudDrawer>
        <MudMainContent>
            <MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pa-4 mt-5">
                <AppBreadcrumb />
                @Body
            </MudContainer>
        </MudMainContent>
    </MudLayout>
</MudRTLProvider>

