using UnityEngine;
using UnityEngine.UI;

namespace GGJ
{
    public class TutorialScreen : MonoBehaviour
    {
        public Image background;
        public Button skipBtn;
        public Image tutorial;

        private int tindex = 0;

        public void StartTutorial()
        {
            var tuts = GameManager.instance.logic.Level.tutorials;
            if (tuts.Count == 0) return;
            background.transform.localPosition = new Vector3(0, Screen.height, 0);
            tutorial.sprite = tuts[0];
            tindex = 0;
            background.gameObject.SetActive(true);
            LeanTween.moveLocalY(background.gameObject, 0, 0.4f).setEaseOutQuad();
            var c = background.color;
            c.a = 0;
            background.color = c;
            LeanTween.alpha(background.rectTransform, 1, 0.6f).setEaseOutQuad().setRecursive(false);
        }

        public void Skip()
        {
            var tuts = GameManager.instance.logic.Level.tutorials;
            var nindex = tindex + 1;
            if (nindex >= tuts.Count)
            {
                StopTutorial();
                return;
            }
            tutorial.sprite = tuts[nindex];
            tindex = nindex;
        }

        public void StopTutorial()
        {
            LeanTween.moveLocalY(background.gameObject, Screen.height, 0.4f)
                .setEaseInQuad()
                .setOnComplete(() => { background.gameObject.SetActive(false); });
        }
    }
}