using UnityEngine;

public class MenuCallbackHolder: MonoBehaviour
{
    private System.Action[] callbacks;

    private AudioSource audioSource;

    private AudioClip zapAudioClip;

    private static readonly string zapAudioClipPath = "Audio/1496_YummyStorm";

    void Start()
    {
        audioSource = GetComponent<AudioSource>();
        zapAudioClip = Resources.Load<AudioClip>(zapAudioClipPath);

        callbacks = new System.Action[]
        {
            PlayButtonCallback,
            InstruccionsButtonCallback,
            SetupButtonCallback,
            ZapButtonCallback,
            AboutButtonCallback,
            QuitButtonCallback
        };
    }

    public void InvokeCallback(int index)
    {
        if (index >= 0 && index < callbacks.Length)
        {
            callbacks[index].Invoke();
        }
        else
        {
            Debug.LogWarning($"MenuCallbackHolder: Invalid callback index {index}");
        }
    }

    public void PlayButtonCallback()
    {
        Debug.Log("Play button pressed");
        UnityEngine.SceneManagement.SceneManager.LoadScene("Game");
    }

    public void InstruccionsButtonCallback()
    {
        Debug.Log("Instructions button pressed");
        // TODO: Implement instructions scene.
    }

    public void SetupButtonCallback()
    {
        Debug.Log("Setup button pressed");
        // TODO: Implement setup dialog.
    }

    public void ZapButtonCallback()
    {
        Debug.Log("Zap Scores button pressed");
        audioSource.PlayOneShot(zapAudioClip);

        // TODO: Add a confirmation dialog before resetting scores
        GameSetup.ZapScores();
    }

    public void AboutButtonCallback()
    {
        Debug.Log("About button pressed");
        // TODO: Implement about dialog.
    }

    public void QuitButtonCallback()
    {
        Debug.Log("Quit button pressed");
        Application.Quit();
    }
}