@using Microsoft.Extensions.Options
@using OpenArchival.Blazor.Config

@inherits LayoutComponentBase


@*
For the login/logout
<AuthorizeView>
        <Authorized>
            <MudNavLink Href="Account/Manage" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Person">@context.User.Identity?.Name</MudNavLink>
            <form action="Account/Logout" method="post">
                <AntiforgeryToken />
                <input type="hidden" name="ReturnUrl" value="@currentUrl" />
                <button type="submit" class="mud-nav-link mud-ripple">
                    <MudIcon Icon="@Icons.Material.Filled.Logout" Color="Color.Info" Class="mr-3"></MudIcon> Logout
                </button>
            </form>
        </Authorized>
        <NotAuthorized>
            <MudNavLink Href="Account/Register" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Person">Register</MudNavLink>
            <MudNavLink Href="Account/Login" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Password">Login</MudNavLink>
        </NotAuthorized>
    </AuthorizeView>
*@

@inject IOptions<ApplicationOptions> Options;
@inject NavigationManager NavigationManager;

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

<MudLayout>
    <MudAppBar Elevation="1" >
            @if (!string.IsNullOrEmpty(Options.Value.NavBarTitle)) {
                <MudNavLink Href="/" Style="max-width:200px;">
                    <MudText Typo="Typo.h6" Class="ml-3">@Options.Value.NavBarTitle</MudText>
                </MudNavLink>
            }
            
            <div class="d-flex justify-center align-center">
                <MudNavLink 
                    Icon="@Icons.Material.Filled.Home" 
                    IconColor=Color.Secondary 
                    Ripple=true 
                    Style="max-width:200px;"
                    Href="/search">
                    Artifacts 
                </MudNavLink>

                <MudNavLink Href="/articles/search" Icon=@Icons.Material.Filled.Book IconColor=Color.Secondary Ripple=true Style="max-width: 200px">
                    Articles 
                </MudNavLink>

                <MudNavLink Href="/about" Icon=@Icons.Material.Filled.QuestionMark IconColor="Color.Secondary" Ripple=true Style="max-width:200px;">
                    About 
                </MudNavLink>
            </div>
            <MudSpacer></MudSpacer>
            <div style="background-color: white; border-radius:10px;" class="pa-2">
                <MudAutocomplete 
                     Placeholder="Search Archive"
                     T="string"
                     Variant="Variant.Filled | Variant.Outlined"
                     AdornmentIcon="@Icons.Material.Filled.Search"
                     Dense=true
                     Underline=false
                     Style="width:200px; --mud-input-text: white; --mud-input-label-text: white;" 
                     OnKeyDown="OnSearchBarKeyDown"
                     @bind-Text=_searchBarText/>
            </div>
            
                 @*
            <MudTextField
                Placeholder="Search"
                Variant="Variant.Filled"
                Adornment="Adornment.Start"
                AdornmentIcon="@Icons.Material.Filled.Search"
                IconSize="Size.Medium"
                T="string">
            </MudTextField>*@
    </MudAppBar>
    <MudMainContent Class="pt-16 pa-4">
        @Body
    </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 string _searchBarText = "";
    private void OnSearchBarKeyDown(KeyboardEventArgs args)
    {
        if (args.Key == "Enter" && !string.IsNullOrEmpty(_searchBarText))
        {
            NavigationManager.NavigateTo($"/search/{System.Web.HttpUtility.UrlEncode(_searchBarText)}");
            _searchBarText = "";
        } 
    }
}


