using DeepDrftModels.DTOs;
using DeepDrftPublic.Client.Services;
using Microsoft.AspNetCore.Components;

namespace DeepDrftPublic.Client.Pages;

public partial class GenresView : ComponentBase
{
    [Inject] public required ITrackDataService TrackData { get; set; }
    [Inject] public required NavigationManager Navigation { get; set; }

    private bool _loading = true;
    private List<GenreSummaryDto> _genres = [];

    protected override async Task OnInitializedAsync()
    {
        var result = await TrackData.GetGenres();
        if (result is { Success: true, Value: { } genres })
            _genres = genres;

        _loading = false;
    }

    private void OpenGenre(string genre)
        => Navigation.NavigateTo($"/archive?genre={Uri.EscapeDataString(genre)}");
}
