using DeepDrftModels.DTOs;
using Microsoft.AspNetCore.Components;

namespace DeepDrftPublic.Client.Controls;

public partial class TracksGallery : ComponentBase
{
    [Parameter] public IEnumerable<TrackDto> Tracks { get; set; } = [];

    // Controlled play-state inputs: the parent owns playback truth (the player service)
    // and drives these. The gallery is presentational — it only matches by id to decide
    // which card reflects the active state.
    [Parameter] public TrackDto? ActiveTrack { get; set; }
    [Parameter] public bool IsPlaying { get; set; }
    [Parameter] public bool IsPaused { get; set; }
    [Parameter] public GalleryViewMode ViewMode { get; set; } = GalleryViewMode.Grid;

    [Parameter] public EventCallback<TrackDto> OnPlay { get; set; }
    [Parameter] public EventCallback<TrackDto> OnPause { get; set; }

    private Task HandlePlayClick(TrackDto track) =>
        OnPlay.HasDelegate ? OnPlay.InvokeAsync(track) : Task.CompletedTask;

    private Task HandlePauseClick(TrackDto track) =>
        OnPause.HasDelegate ? OnPause.InvokeAsync(track) : Task.CompletedTask;
}
