@using Moonlight.App.Services.Files
@using Moonlight.App.Services.Sessions

@inject ResourceService ResourceService
@inject DynamicBackgroundService DynamicBackgroundService
@inject IdentityService IdentityService

<div class="d-flex flex-column flex-root app-root">
<div class="app-page flex-column flex-column-fluid">
<!-- Page Header -->

<div class="app-header">
    <div class="app-container container-fluid d-flex align-items-stretch justify-content-between">
        <div class="d-flex align-items-center d-lg-none ms-n2 me-2" title="Show sidebar menu">
            <a class="btn btn-icon btn-active-color-primary w-35px h-35px" @onclick:preventDefault @onclick="ToggleMobileSidebar">
                <i class="bx bx-menu bx-md"></i>
            </a>
        </div>

        @if (ShowMobileSidebar)
        {
            <div style="z-index: 105;" class="drawer-overlay" @onclick="ToggleMobileSidebar"></div>
        }

        <div class="d-flex align-items-center flex-grow-1 flex-lg-grow-0">
            <a href="/" class="d-lg-none">
                <img alt="Logo" src="@(ResourceService.Image("logo.svg"))" class="h-30px"/>
            </a>
        </div>
        <div class="d-flex align-items-stretch justify-content-between flex-lg-grow-1">
            <div class="app-header-menu app-header-mobile-drawer align-items-stretch">
                <div class="menu menu-rounded menu-column menu-lg-row my-5 my-lg-0 align-items-stretch fw-semibold px-2 px-lg-0">
                </div>
            </div>
            <Navbar></Navbar>
        </div>
    </div>
</div>

<!-- Page Header End --->
<div class="app-wrapper flex-column flex-row-fluid">
<!-- Sidebar -->

<div class="app-sidebar flex-column @(ShowMobileSidebar ? "drawer drawer-start drawer-on" : "")">
<div class="app-sidebar-logo px-6">
    <a href="@(IdentityService.User != null ? "/" : "/login")">
        <img alt="Logo" src="@(ResourceService.Image("logolong.png"))" class="h-45px app-sidebar-logo-default"/>
        <img alt="Logo" src="@(ResourceService.Image("logo.svg"))" class="h-20px app-sidebar-logo-minimize"/>
    </a>
</div>

<div class="app-sidebar-menu overflow-hidden flex-column-fluid">
<div class="app-sidebar-wrapper hover-scroll-overlay-y my-5">
<div class="menu menu-column menu-rounded menu-sub-indention px-3">
@if (IdentityService.User == null)
{
    <div class="menu-item">
        <a class="menu-link" href="/login">
            <span class="menu-icon">
                <i class="bx bxs-log-in"></i>
            </span>
            <span class="menu-title">
                <TL>Login</TL>
            </span>
        </a>
    </div>
    <div class="menu-item">
        <a class="menu-link" href="/register">
            <span class="menu-icon">
                <i class="bx bx-user-plus"></i>
            </span>
            <span class="menu-title">
                <TL>Register</TL>
            </span>
        </a>
    </div>
}
else
{
    <div class="menu-item">
        <a class="menu-link" href="/">
            <span class="menu-icon">
                <i class="bx bx-layer"></i>
            </span>
            <span class="menu-title">
                <TL>Dashboard</TL>
            </span>
        </a>
    </div>
    <div class="menu-item">
        <a class="menu-link" href="/servers">
            <span class="menu-icon">
                <i class="bx bx-server"></i>
            </span>
            <span class="menu-title">
                <TL>Servers</TL>
            </span>
        </a>
    </div>
    <div class="menu-item">
        <a class="menu-link" href="/webspaces">
            <span class="menu-icon">
                <i class="bx bx-globe"></i>
            </span>
            <span class="menu-title">
                <TL>Webspaces</TL>
            </span>
        </a>
    </div>
    <div class="menu-item">
        <a class="menu-link" href="/domains">
            <span class="menu-icon">
                <i class="bx bx-purchase-tag"></i>
            </span>
            <span class="menu-title">
                <TL>Domains</TL>
            </span>
        </a>
    </div>

    if (IdentityService.Permissions.HasAnyPermissions())
    {
        <div class="menu-item pt-5">
            <div class="menu-content">
                <span class="menu-heading fw-bold text-uppercase fs-7">
                    <TL>Admin</TL>
                </span>
            </div>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin">
                <span class="menu-icon">
                    <i class="bx bx-layer"></i>
                </span>
                <span class="menu-title">
                    <TL>Dashboard</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/system">
                <span class="menu-icon">
                    <i class="bx bx-chip"></i>
                </span>
                <span class="menu-title">
                    <TL>System</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/security">
                <span class="menu-icon">
                    <i class="bx bx-shield"></i>
                </span>
                <span class="menu-title">
                    <TL>Security</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/servers">
                <span class="menu-icon">
                    <i class="bx bx-server"></i>
                </span>
                <span class="menu-title">
                    <TL>Servers</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/webspaces">
                <span class="menu-icon">
                    <i class="bx bx-globe"></i>
                </span>
                <span class="menu-title">
                    <TL>Webspaces</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/users">
                <span class="menu-icon">
                    <i class="bx bx-user"></i>
                </span>
                <span class="menu-title">
                    <TL>Users</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/domains">
                <span class="menu-icon">
                    <i class="bx bx-purchase-tag"></i>
                </span>
                <span class="menu-title">
                    <TL>Domains</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/support">
                <span class="menu-icon">
                    <i class="bx bx-support"></i>
                </span>
                <span class="menu-title">
                    <TL>Support</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/subscriptions">
                <span class="menu-icon">
                    <i class="bx bx-credit-card"></i>
                </span>
                <span class="menu-title">
                    <TL>Subscriptions</TL>
                </span>
            </a>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/statistics">
                <span class="menu-icon">
                    <i class="bx bx-objects-vertical-bottom"></i>
                </span>
                <span class="menu-title">
                    <TL>Statistics</TL>
                </span>
            </a>
        </div>

        <div class="menu-item">
            <a class="menu-link" href="/admin/changelog">
                <span class="menu-icon">
                    <i class="bx bx-notepad"></i>
                </span>
                <span class="menu-title">
                    <TL>Changelog</TL>
                </span>
            </a>
        </div>
    }
}
</div>
</div>
</div>

<div class="app-sidebar-footer flex-column-auto pt-2 pb-6 px-6">
    <a href="/support" class="btn btn-flex flex-center btn-custom btn-primary overflow-hidden text-nowrap px-0 h-40px w-100 btn-label">
        <i class="bx bx-sm bx-support"></i>
    </a>
</div>
</div>

<!-- Sidebar End -->

<div class="app-main flex-column flex-row-fluid">
    <div class="d-flex flex-column flex-column-fluid">
        <div class="app-content flex-column-fluid" style="background-position: center; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-image: linear-gradient(rgba(0, 0, 0, 0.55),rgba(0, 0, 0, 0.55)) ,url('@(DynamicBackgroundService.BackgroundImageUrl)');">
            <div class="app-container container-fluid">
                <div class="mt-10">
                    @ChildContent
                </div>
            </div>
        </div>
    </div>
    <Footer></Footer>
</div>
</div>
</div>
</div>

@code
{
    [Parameter]
    public RenderFragment ChildContent { get; set; }

    private bool ShowMobileSidebar = false;

    private async Task ToggleMobileSidebar()
    {
        ShowMobileSidebar = !ShowMobileSidebar;
        await InvokeAsync(StateHasChanged);
    }
}