using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tuto : MonoBehaviour
{
    #region Fields
    [SerializeField] private GameObject _panelPosition = null;
    [SerializeField] private GameObject _panelRotation = null;
    [SerializeField] private GameObject _panelCurve = null;
    [SerializeField] private GameObject _panelLaunch = null;
    [SerializeField] private BunkerStationLaunch _launchButton = null;
    [SerializeField] private List<BunkerStationCurve> _curves = null;
    #endregion Fields

    #region Properties
    #endregion Properties

    #region Methods
    private void Start()
    {
        Hide();
        _launchButton.LaunchButtonPressedEvent += OnLaunchButtonPressed;
        foreach (BunkerStationCurve curve in _curves)
        {
            curve.InteractEvent += OnInteract;
        }
        GameManager.Instance.GameStateChanged += OnGameStateChanged;
    }

    private void OnDestroy()
    {
        _launchButton.LaunchButtonPressedEvent -= OnLaunchButtonPressed;
        foreach (BunkerStationCurve curve in _curves)
        {
            curve.InteractEvent -= OnInteract;
        }
        GameManager.Instance.GameStateChanged -= OnGameStateChanged;
    }


    public void OnGameStateChanged(GameState state)
    {
        if (GameManager.Instance.UseTuto == false)
        {
            return;
        }
        if (state == GameState.TrajectoryMix)
        {
            DisplayPosition();
        }
        if (state == GameState.EndMenu)
        {
            Hide();
        }
    }

    public void OnLaunchButtonPressed(StationLaunchMode stationLaunchMode)
    {
        if (GameManager.Instance.UseTuto == false)
        {
            return;
        }
        switch (stationLaunchMode)
        {
            case StationLaunchMode.POSITION:
                {
                    DisplayCurves();
                }
                break;
            case StationLaunchMode.LAUNCH:
                {
                    GameManager.Instance.UseTuto = false;
                    GameSceneManager.Instance.WaveManager.LaunchWaves();
                    Hide();
                }
                break;
            default:
                break;
        }
    }

    public void Hide()
    {
        UnityEngine.Debug.Log("Hide");
        _panelPosition.SetActive(false);
        _panelRotation.SetActive(false);
        _panelCurve.SetActive(false);
        _panelLaunch.SetActive(false);
    }


    public void OnInteract()
    {
        DisplayLaunch();
    }

    public void DisplayPosition()
    { 
        if (GameManager.Instance.UseTuto == false)
        {
            return;
        }
        UnityEngine.Debug.Log("DisplayPosition");

        _panelPosition.SetActive(true);
        _panelRotation.SetActive(false);
        _panelCurve.SetActive(false);
        _panelLaunch.SetActive(false);
    }

    public void DisplayRotation()
    {
        UnityEngine.Debug.Log("DisplayRotation");
        if (GameManager.Instance.UseTuto == false)
        {
            return;
        }

        _panelPosition.SetActive(false);
        _panelRotation.SetActive(true);
        _panelCurve.SetActive(false);
        _panelLaunch.SetActive(false);
    }

    public void DisplayCurves()
    {
        UnityEngine.Debug.Log("DisplayCurves");
        if (GameManager.Instance.UseTuto == false)
        {
            return;
        }

        _panelPosition.SetActive(false);
        _panelRotation.SetActive(false);
        _panelCurve.SetActive(true);
        _panelLaunch.SetActive(false);
    }

    public void DisplayLaunch()
    {
        UnityEngine.Debug.Log("DisplayLaunch");
        if (GameManager.Instance.UseTuto == false)
        {
            return;
        }

        _panelPosition.SetActive(false);
        _panelRotation.SetActive(false);
        _panelCurve.SetActive(false);
        _panelLaunch.SetActive(true);
    }
    #endregion Methods
}
