using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class SongCard : MonoBehaviour
{
    [SerializeField] private TMP_Text   titleText;
    [SerializeField] private TMP_Text   artistText;
    [SerializeField] private TMP_Text   durationText;
    [SerializeField] private GameObject downloadedBadge;
    [SerializeField] private Button     button;

    public void Setup(SongInfo song, bool isDownloaded, Action onClick)
    {
        titleText.text    = song.title;
        artistText.text   = song.artist;
        durationText.text = FormatDuration(song.duration);
        downloadedBadge.SetActive(isDownloaded);
        button.onClick.AddListener(() => onClick?.Invoke());
    }

    private static string FormatDuration(int seconds)
        => $"{seconds / 60}:{seconds % 60:D2}";
}
