@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Identity
@using MudBlazor
@using OpenArchival.DataAccess

@inherits LayoutComponentBase
@rendermode InteractiveServer

<MudThemeProvider />
<MudPopoverProvider /> 
<MudDialogProvider />
<MudSnackbarProvider />

<MudLayout>
    <MudAppBar Elevation="1">
        <MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@ToggleDrawer" />
        <MudText Typo="Typo.h5" Class="ml-3">Admin Console</MudText>
        <MudSpacer />
        <MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End" />
    </MudAppBar>

    <MudDrawer @bind-Open="_drawerOpen" ClipMode="DrawerClipMode.Always" Elevation="2">
        <MudNavMenu>
            <MudNavLink Href="/admin/archiveadmin" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Dashboard">Archive Entry Management</MudNavLink>
            <MudNavLink Href="/admin/userstable" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Person">User Management</MudNavLink>
            <MudNavLink Href="/admin/searchpage" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Search">Search Page Settings</MudNavLink>
            <MudNavLink Href="/admin/homepageeditor" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home Page Editor</MudNavLink>
            <MudNavLink Href="/admin/aboutpageeditor" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.QuestionMark">About Page Editor</MudNavLink>

            <MudNavGroup Title="Blog" Icon="@Icons.Material.Filled.Book">
                <MudNavLink Href="/admin/blogedit" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Edit">Create Blog Post</MudNavLink>
                <MudNavLink Href="/admin/blogstable" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Edit">Edit Blog Posts</MudNavLink>
            </MudNavGroup>
            <form method="post" action="/Logout" data-enhance="false">
                <AntiforgeryToken/>
                <MudButton ButtonType="ButtonType.Submit"
                           Variant="Variant.Text"
                           Color="Color.Error"
                           StartIcon="@Icons.Material.Filled.Logout">
                    Logout
                </MudButton>
            </form>
            </MudNavMenu>
    </MudDrawer>

    <MudMainContent>
        <MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pa-8">
            @Body
        </MudContainer>
    </MudMainContent>
</MudLayout>

<div id="blazor-error-ui" data-nosnippet>
    An unhandled error has occurred.
    <a href="." class="reload">Reload</a>
    <span class="dismiss">🗙</span>
</div>

@code {
    private bool _drawerOpen = true;

    private void ToggleDrawer()
    {
        _drawerOpen = !_drawerOpen;
    }
}
