using Cinemachine;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CamPosController : MonoBehaviour
{
    public Animator cameraAnimator;
    Camera mainCamera;

    CinemachineStateDrivenCamera cameras;

    [Header("WinElements")]
    public GameObject winPanel;

    void Start()
    {
        mainCamera = Camera.main;
        cameras = GetComponent<CinemachineStateDrivenCamera>();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.B))
        {
            StartCoroutine(WinCoroutine());
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            cameraAnimator.Play("MainMenuCam");
        }
    }

    IEnumerator WinCoroutine()
    {
        cameraAnimator.Play("BackCam");
        yield return new WaitForSecondsRealtime(5.0f);
        winPanel.SetActive(true);
    }

    IEnumerator OutLevelCoroutine(string NextLevel)
    {
        cameraAnimator.Play("OutLevelCam");
        yield return new WaitForSecondsRealtime(1.5f);
        TransitionManager.instance.ChangeScene(NextLevel);
    }

    public void p_NextLevel(string NextLevel)
    {
        StartCoroutine(OutLevelCoroutine(NextLevel));
        
    }

    public void p_RetryLevel()
    {
        TransitionManager.instance.ChangeScene(SceneManager.GetActiveScene().buildIndex);
    }

    public void p_MainMenu()
    {
        TransitionManager.instance.ChangeScene("MainMenu");
    }
}
