/*
 * author: mark joshwel
 * date: 29/5/2024
 * description: main menu script for handling main menu button functions
 */

using UnityEngine;
using UnityEngine.UIElements;

/// <summary>
/// class managing the main menu and button function invocations
/// </summary>
public class MainMenu : CommonMenu
{
    /// <summary>
    /// button to play game
    /// </summary>
    public Button ButtonPlay;
    
    /// <summary>
    /// button to show options menu
    /// </summary>
    public Button ButtonOptions;
    
    /// <summary>
    /// button to show credits menu
    /// </summary>
    public Button ButtonCredits;
    
    /// <summary>
    /// button to quit game
    /// </summary>
    public Button ButtonExit;

    /// <summary>
    /// function to associate a display state with the menu,
    /// and subscribe button events to their respective functions
    /// </summary>
    public override void OnEnable()
    {
        associatedState = GameManager.DisplayState.ScreenMainMenu;
        base.OnEnable();

        // get the start button from the ui root and subscribe appropriate functions
        ButtonPlay = UI.Q<Button>("ButtonPlay");
        ButtonPlay.clicked += PlayClick;
        ButtonPlay.clicked += OptionStartGame;

        // get the options button from the ui root and subscribe appropriate functions
        ButtonOptions = UI.Q<Button>("ButtonOptions");
        ButtonOptions.clicked += PlayClick;
        ButtonOptions.clicked += OptionShowOptions;

        // get the credits button from the ui root and subscribe appropriate functions
        ButtonCredits = UI.Q<Button>("ButtonCredits");
        ButtonCredits.clicked += PlayClick;
        ButtonCredits.clicked += OptionShowCredits;

        // get the quit button from the ui root and subscribe appropriate functions
        ButtonExit = UI.Q<Button>("ButtonExit");
        ButtonExit.clicked += PlayClick;
        ButtonExit.clicked += OptionQuitGame;
    }

    /// <summary>
    /// handles start button press,
    /// signals the game manager appropriately
    /// </summary>
    private void OptionStartGame()
    {
        // start game
        Game.SetDisplayState(GameManager.DisplayState.Game);
    }

    /// <summary>
    /// handles credits button press,
    /// signals the game manager appropriately
    /// </summary>
    private void OptionShowCredits()
    {
        // show credits menu
        Game.SetDisplayState(GameManager.DisplayState.ScreenCreditsMenu);
    }

    /// <summary>
    /// handles options button press,
    /// signals the game manager appropriately
    /// </summary>
    private void OptionShowOptions()
    {
        // show options menu
        Game.SetDisplayState(GameManager.DisplayState.ScreenOptionsMenu);
    }

    /// <summary>
    /// handles quit button press,
    /// signals the game manager appropriately
    /// </summary>
    private void OptionQuitGame()
    {
        // quit game
        // TODO: do we need to integrate this with the game manager?
        Debug.Log("quit button pressed");
        Game.Quit();
    }
}