@inherits LayoutComponentBase

<MudThemeProvider @ref=_mudThemeProvider IsDarkMode=_isDarkMode Theme=_theme/>
<MudDialogProvider/>
<MudSnackbarProvider/>

<MudLayout>
    <MudAppBar>
        <MudIconButton Icon="@Icons.Material.Filled.Menu" Color=Color.Inherit Edge=Edge.Start OnClick="@((e) => DrawerToggle())"></MudIconButton>
        Gottfrieds Nackenbox
        <MudSwitch @bind-Checked="@_isDarkMode" Color="Color.Primary" Class="ma-4" T="bool" Label="Toggle Light/Dark Mode"/>
    </MudAppBar>
    <MudDrawer @bind-Open=_drawerOpen>
        <NavMenu />
    </MudDrawer>

    <MudMainContent>
        @Body
    </MudMainContent>
</MudLayout>

@code
{
    private MudTheme _theme = new();
    //{
    //    Palette = new Palette()
    //    {
    //        Primary = Colors.Green.Darken1,
    //        Secondary = Colors.Orange.Darken4,
    //        AppbarBackground =  Colors.Green.Darken1,
    //    },
    //    PaletteDark = new Palette()
    //    {
    //        Primary = Colors.Blue.Lighten1
    //    },

    //    LayoutProperties = new LayoutProperties()
    //    {
    //        DrawerWidthLeft = "260px",
    //        DrawerWidthRight = "300px"
    //    }
    //};

    private MudThemeProvider? _mudThemeProvider;

    bool _isDarkMode = false;
    bool _drawerOpen = true;

    void DrawerToggle()
    {
        _drawerOpen = !_drawerOpen;
    }
    
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            _isDarkMode = await _mudThemeProvider!.GetSystemPreference();
            StateHasChanged();
        }
    }
}
