using TMPro;
using UnityEngine;
using System;

namespace MenuMap
{
    public class DialoguePanel: PageAnimation
    {
        public static Action<string> UpdateText;
        public static Action<bool> ShowDialogues;
        public static Action<bool> ShowOpenKey;

        [SerializeField] private TextMeshProUGUI dialogueText;
        [SerializeField] private GameObject openKey;

        public void Start()
        {
            base.Start();
            UpdateText += ShowDialogue;
            ShowDialogues += DialogSetActive;
            ShowOpenKey += OpenKeySetActive;
        }

        private void OnDestroy()
        {
            UpdateText -= ShowDialogue;
            ShowDialogues -= DialogSetActive;
            ShowOpenKey -= OpenKeySetActive;
        }

        private void DialogSetActive(bool active)
        {
            if (active) OpenPage();
            else ClosePage();
        }
        
        private void OpenKeySetActive(bool active)
        {
            openKey.SetActive(active);
        }

        void ShowDialogue(string text)
        {
            dialogueText.text = text;
        }
    }
}