using UnityEngine;
using UnityEngine.UIElements;

/// <summary>
///     singleton for a single source of truth game state and flow management
/// </summary>
public class SideViewUI : MonoBehaviour
{
    /// <summary>
    ///     settings button for showing the settings menu
    /// </summary>
    private Button _accountButton;

    /// <summary>
    ///     leaderboard button for showing the leaderboard
    /// </summary>
    private Button _leaderboardButton;

    /// <summary>
    ///     play button for starting the game
    /// </summary>
    private Button _playButton;

    /// <summary>
    ///     function to subscribe button events to their respective functions
    /// </summary>
    private void OnEnable()
    {
        var ui = GetComponent<UIDocument>().rootVisualElement;

        _playButton = ui.Q<Button>("PlayButton");
        _playButton.clicked += OnPlayButtonClicked;

        _leaderboardButton = ui.Q<Button>("LeaderboardButton");
        _leaderboardButton.clicked += OnLeaderboardButtonClicked;

        _accountButton = ui.Q<Button>("AccountButton");
        _accountButton.clicked += OnAccountButtonClicked;
    }

    /// <summary>
    ///     function to show the play view
    /// </summary>
    private static void OnPlayButtonClicked()
    {
        GameManager.Instance.ui.SetDisplayState(UIManager.DisplayState.PlayView);
    }

    /// <summary>
    ///     function to show the leaderboard view
    /// </summary>
    private static void OnLeaderboardButtonClicked()
    {
        GameManager.Instance.ui.SetDisplayState(UIManager.DisplayState.LeaderboardView);
    }

    /// <summary>
    ///     function to show the account view
    /// </summary>
    private static void OnAccountButtonClicked()
    {
        GameManager.Instance.ui.SetDisplayState(UIManager.DisplayState.AccountView);
    }
}