@inherits FnzComponentBase
@inject LocalStorageHelper localStorage

@code {
    [Parameter] public string CssClass { get; set; }
}

@if (CurrentTheme != null && CurrentTheme != "default")
{
    <link href="lib/bootstrap/bootswatch/@CurrentTheme/bootstrap.min.css" rel="stylesheet" />
}

@code {

    private static readonly IReadOnlyCollection<string> Themes = new[] {
        "Cerulean","Cosmo","Cyborg","Darkly","Flatly","Journal","Litera","Lumen","Lux","Materia",
        "Minty","Morph","Pulse","Quartz","Sandstone","Simplex","Sketchy","Slate","Solar","Spacelab",
        "Superhero","United","Vapor","Yeti","Zephyr"
    };

    private string CurrentTheme { get => localStorage.Get<string>(); set => localStorage.Set(value); }

    private void SetTheme(string name)
    {
        CurrentTheme = name;
        StateHasChanged();
    }
}

<button class="btn btn-primary dropdown-toggle active @CssClass" @attributes="@InputAttributes" data-bs-toggle="dropdown">@CurrentTheme</button>
<div class="dropdown-menu" aria-labelledby="themes" data-bs-popper="static">
    <a class="dropdown-item" @onclick="@(()=>SetTheme("default"))">Default</a>
    <div class="dropdown-divider"></div>

    @foreach (var item in Themes)
    {
        <a class="dropdown-item @(CurrentTheme==item.ToLower()?"active":"")" @onclick="@(()=>SetTheme(item))">@item</a>
    }

</div>
