@using DeepDrftModels.DTOs
@if (IsLoading)
{
}
else if (Genres.Count == 0)
{
No genres found.
}
else
{
@foreach (var genre in Genres)
{
var isExpanded = ExpandedGenre == genre.Genre;
ToggleGenre(genre.Genre))">
@genre.Genre
@genre.TrackCount track(s)
}
@if (ExpandedGenre is not null)
{
@ExpandedGenre
}
}
@code {
[Parameter] public IReadOnlyList Genres { get; set; } = Array.Empty();
[Parameter] public bool IsLoading { get; set; }
[Parameter] public string? ExpandedGenre { get; set; }
[Parameter] public EventCallback OnExpandedGenreChanged { get; set; }
// The view model owns the toggle (selecting the open genre collapses it), so we pass the raw
// clicked genre rather than pre-computing the next state here — keeps the toggle logic single-sourced.
private async Task ToggleGenre(string genre) =>
await OnExpandedGenreChanged.InvokeAsync(genre);
private static string SwatchClass(bool isExpanded) =>
isExpanded ? "cms-genre-swatch cms-genre-swatch--active" : "cms-genre-swatch";
}