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

namespace DeepDrftPublic.Client.Controls;

public partial class TrackCard : ComponentBase
{
    [Parameter] public required TrackDto TrackModel { get; set; }
    [Parameter] public EventCallback<TrackDto> OnPlay { get; set; }
    [Parameter] public EventCallback<TrackDto> OnPause { get; set; }
    [Parameter] public bool IsPlaying { get; set; } = false;
    [Parameter] public bool IsPaused { get; set; } = false;
    [Parameter] public GalleryViewMode ViewMode { get; set; } = GalleryViewMode.Grid;

    // Pause only when actively playing; every other state (idle, paused) reads as "press to play".
    private bool IsActivelyPlaying => IsPlaying && !IsPaused;

    private string PlayPauseIcon =>
        IsActivelyPlaying ? Icons.Material.Filled.Pause : Icons.Material.Filled.PlayArrow;

    private async Task PlayClick()
    {
        if (IsActivelyPlaying)
        {
            if (OnPause.HasDelegate)
                await OnPause.InvokeAsync(TrackModel);
        }
        else if (OnPlay.HasDelegate)
        {
            await OnPlay.InvokeAsync(TrackModel);
        }
    }
}
