@using Moonlight.App.Services
@using Moonlight.App.Services.Sessions
@using Moonlight.App.Database.Entities

@inject IdentityService IdentityService

<div class="app-sidebar-menu overflow-hidden flex-column-fluid">
<div id="kt_app_sidebar_menu_wrapper" class="app-sidebar-wrapper hover-scroll-overlay-y my-5" data-kt-scroll="true" data-kt-scroll-activate="true" data-kt-scroll-height="auto" data-kt-scroll-dependencies="#kt_app_sidebar_logo, #kt_app_sidebar_footer" data-kt-scroll-wrappers="#kt_app_sidebar_menu" data-kt-scroll-offset="5px" data-kt-scroll-save-state="true">
<div class="menu menu-column menu-rounded menu-sub-indention px-3" id="#kt_app_sidebar_menu" data-kt-menu="true" data-kt-menu-expand="false">
@if (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="/websites">
            <span class="menu-icon">
                <i class="bx bx-globe"></i>
            </span>
            <span class="menu-title"><TL>Websites</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>
    <div class="menu-item">
        <a class="menu-link" href="/changelog">
            <span class="menu-icon">
                <i class="bx bx-notepad"></i>
            </span>
            <span class="menu-title"><TL>Changelog</TL></span>
        </a>
    </div>

    if (User.Admin)
    {
        <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 data-kt-menu-trigger="click" class="menu-item menu-accordion">
            <span class="menu-link">
                <span class="menu-icon">
                    <i class="bx bx-server"></i>
                </span>
                <span class="menu-title"><TL>Servers</TL></span>
                <span class="menu-arrow"></span>
            </span>
            <div class="menu-sub menu-sub-accordion">
                <div class="menu-item">
                    <a class="menu-link" href="/admin/servers">
                        <span class="menu-bullet">
                            <span class="bullet bullet-dot"></span>
                        </span>
                        <span class="menu-title"><TL>Overview</TL></span>
                    </a>
                </div>

                <div class="menu-item">
                    <a class="menu-link" href="/admin/servers/manager">
                        <span class="menu-bullet">
                            <span class="bullet bullet-dot"></span>
                        </span>
                        <span class="menu-title"><TL>Manager</TL></span>
                    </a>
                </div>

                <div class="menu-item">
                    <a class="menu-link" href="/admin/servers/cleanup">
                        <span class="menu-bullet">
                            <span class="bullet bullet-dot"></span>
                        </span>
                        <span class="menu-title"><TL>Cleanup</TL></span>
                    </a>
                </div>

                <div class="menu-item">
                    <a class="menu-link" href="/admin/nodes">
                        <span class="menu-bullet">
                            <span class="bullet bullet-dot"></span>
                        </span>
                        <span class="menu-title"><TL>Nodes</TL></span>
                    </a>
                </div>

                <div class="menu-item">
                    <a class="menu-link" href="/admin/servers/images">
                        <span class="menu-bullet">
                            <span class="bullet bullet-dot"></span>
                        </span>
                        <span class="menu-title"><TL>Images</TL></span>
                    </a>
                </div>
            </div>
        </div>
        <div class="menu-item">
            <a class="menu-link" href="/admin/websites">
                <span class="menu-icon">
                    <i class="bx bx-globe"></i>
                </span>
                <span class="menu-title"><TL>Websites</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 data-kt-menu-trigger="click" class="menu-item menu-accordion">
            <span class="menu-link">
                <span class="menu-icon">
                    <i class="bx bx-purchase-tag"></i>
                </span>
                <span class="menu-title"><TL>Domains</TL></span>
                <span class="menu-arrow"></span>
            </span>
            <div class="menu-sub menu-sub-accordion">
                <div class="menu-item">
                    <a class="menu-link" href="/admin/domains/">
                        <span class="menu-bullet">
                            <span class="bullet bullet-dot"></span>
                        </span>
                        <span class="menu-title"><TL>Domains</TL></span>
                    </a>
                </div>
                <div class="menu-item">
                    <a class="menu-link" href="/admin/domains/shared">
                        <span class="menu-bullet">
                            <span class="bullet bullet-dot"></span>
                        </span>
                        <span class="menu-title"><TL>Shared domains</TL></span>
                    </a>
                </div>
            </div>
        </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>
</div>
</div>

@code
{
    private User? User;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            User = await IdentityService.Get();

            await InvokeAsync(StateHasChanged);
        }
    }
}