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

public class TutorialPanelGestor : MonoBehaviour
{
    [SerializeField] GameObject[] TutorialPanels;
    int CurrentIndex = 0;
    RoundsManager RM;
    CharacterController2D CC2d;

    private void Awake()
    {
        CC2d = CharacterController2D.instance.GetComponent<CharacterController2D>();
        foreach (GameObject panel in TutorialPanels)
        {
            panel.SetActive(false);
        }
    }

    private void Start()
    {
        RM = RoundsManager.instance.gameObject.GetComponent<RoundsManager>();
        RM.OnRoundFinished.AddListener(ActivatePanel);
    }

    public void ActivatePanel()
    {
        if(CurrentIndex < TutorialPanels.Length)
        {
            CC2d.CanDoActions = false;
            TutorialPanels[CurrentIndex].SetActive(true);
            CurrentIndex++;
            Time.timeScale = 0;
        }
    }

    public void DeactivatePanel(int index)
    {
        Invoke("AllowPlayerActions", 0.5f);
        TutorialPanels[index].SetActive(false);
        Time.timeScale = 1;
    }

    private void AllowPlayerActions()
    {
        CC2d.CanDoActions = true;
    }
}
