@inherits LayoutComponentBase
@using Microsoft.AspNetCore.Components.Authorization;
@using System.Security.Claims;
@inject AuthenticationStateProvider AuthenticationStateProvider

<Layout Class="layout">
    <MainMenu>
        <MenuItem RouterLink="/Dashboard">Dashboard</MenuItem>
        @if (User != null && User.IsInRole("Administrator"))
        {
            <MenuItem RouterLink="/Games">Games</MenuItem>
            <MenuItem RouterLink="/Collections">Collections</MenuItem>
            <MenuItem RouterLink="/Redistributables">Redistributables</MenuItem>
            <MenuItem RouterLink="/Servers">Servers</MenuItem>
            <MenuItem RouterLink="/Files">Files</MenuItem>
            <SubMenu Title="Settings">
                <MenuItem RouterLink="/Settings/General">General</MenuItem>
                <MenuItem RouterLink="/Settings/Users">Users</MenuItem>
                <MenuItem RouterLink="/Settings/Authentication">Authentication</MenuItem>
                <MenuItem RouterLink="/Settings/UserSaves">User Saves</MenuItem>
                <MenuItem RouterLink="/Settings/Archives">Archives</MenuItem>
                <MenuItem RouterLink="/Settings/Media">Media</MenuItem>
                <MenuItem RouterLink="/Settings/IPXRelay">IPX Relay</MenuItem>
                <MenuItem RouterLink="/Settings/Beacon">Beacon</MenuItem>
                <MenuItem RouterLink="/Settings/Tools">Tools</MenuItem>
            </SubMenu>
        }
        <SubMenu Title="Profile">
            <MenuItem RouterLink="/Profile">General</MenuItem>
            <MenuItem RouterLink="/Profile/ChangePassword">Change Password</MenuItem>
            <MenuItem RouterLink="/Profile/Saves">Saves</MenuItem>
            <MenuItem RouterLink="/Identity/Account/Logout">Logout</MenuItem>
        </SubMenu>
    </MainMenu>

    <Content Style="padding: 24px; min-height: 100vh;">
        @Body
    </Content>
</Layout>

@code {
    ClaimsPrincipal User;

    protected override async Task OnInitializedAsync()
    {
        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

        if (authState.User.Identity.IsAuthenticated)
            User = authState.User;
    }
}