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

namespace ToadieTechnika.GGJ2018Game
{
    public class MenuController : MonoBehaviour
    {
        [SerializeField]
        GameObject m_ContinueButton;
        bool m_isInit;

        #region Unity Functions
        void Start()
        {
            NormalizeMenu();
            m_isInit = true;
        }

        void OnEnable()
        {
            if (m_isInit)
                NormalizeMenu();
        } 
        #endregion

        #region Functions
        void NormalizeMenu()
        {
            GameController.instance.PlayerDataManipulation(PlayerDataState.Load);
            m_ContinueButton.SetActive(GameController.instance.PlayerData.CurrentLevel > 0);
        }

        public void ButtonCallback(int _GetIndex)
        {
            switch (_GetIndex)
            {
                case 0: //Start (New Game)
                    GameController.instance.PlayerData.CurrentLevel = 0;
                    TransitionScript.instance.TransitionInit(delegate 
                    {
                        PanelsController.instance.ChangePanel(Panels.Gameplay);
                    });
                    break;
                case 1: //Continue
                    TransitionScript.instance.TransitionInit(delegate
                    {
                        PanelsController.instance.ChangePanel(Panels.Gameplay);
                    });
                    break;
            }

            GameController.instance.PlaySound(SFX.GameButton);
        } 
        #endregion
    }
}