@inherits ViewBase
 
<div class="row mt-2">
    <div class="col">
        <LibSelector CurrentLibrary="@CurrentLibrary" OnValueChanged="SelectedLibraryChanged"></LibSelector>
    </div>
</div>

<div class="row mt-2">
    <div class="row">
        <div class="col">
            <LibTrackSet CurrentLibrary="@CurrentLibrary"></LibTrackSet>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-12">
        <div class="row">
            @foreach (var disc in (CurrentLibrary?.Discs).KeepNoEmpty())
            {
                <DiscCard Disc="disc"></DiscCard>
            }
        </div>
    </div>
</div>


@code {
    private string CurrentLibraryKey { get => LocalStorage.Get<string>(); set => LocalStorage.Set(value); }
    private FeLibrary CurrentLibrary { get; set; }

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        if (DataSet.AllLibrary?.Any() == true)
        {
            var clk = CurrentLibraryKey;
            if (DataSet.AllLibrary.Any(p => p.Key == clk)) SelectedLibraryChanged(DataSet.AllLibrary.First(p => p.Key == clk));
            if (CurrentLibrary == null) SelectedLibraryChanged(DataSet.AllLibrary.First());
        }
    }

    public void SelectedLibraryChanged(FeLibrary lib)
    {
        CurrentLibrary = lib;
        CurrentLibraryKey = lib.Key;
        StateHasChanged();
    }
}
