using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class NewGamesButtonPanelScript : MonoBehaviour
{
    private const string MainMenuSceneName = "MainMenu";
    public Button localGameButton;
    public Button onlineGameButton;
    public GameObject localGameSettingsPanel;
    public GameObject onlineGameSettingsPanel;
    public GameObject buttonPanel;
    [SerializeField] GameObject informationPanel;

    private Button backButton;
    // Start is called before the first frame update
    void Start()
    {
        backButton = informationPanel.GetComponent<InformationPanelScript>().getBackButton();
        localGameButton.onClick.AddListener(ShowLocalGameSettings);
        onlineGameButton.onClick.AddListener(ShowOnlineGameSettings);
        backButton.onClick.AddListener(() => SceneManager.LoadScene(MainMenuSceneName));
    }

    void ShowLocalGameSettings() {
        buttonPanel.SetActive(false);
        localGameSettingsPanel.SetActive(true);
        backButton.onClick.RemoveAllListeners();
        backButton.onClick.AddListener(BackButtonListenerToButtonPanel);
    }

    void ShowOnlineGameSettings() {
        gameObject.SetActive(false);
        onlineGameSettingsPanel.SetActive(true);
        backButton.onClick.RemoveAllListeners();
        backButton.onClick.AddListener(BackButtonListenerToButtonPanel);
    }

    void BackButtonListenerToButtonPanel() {
        onlineGameSettingsPanel.SetActive(false);
        localGameSettingsPanel.SetActive(false);
        gameObject.SetActive(true);
        backButton.onClick.RemoveAllListeners();
        backButton.onClick.AddListener(() => SceneManager.LoadScene(MainMenuSceneName));
    }
}
