using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UITutorial : MonoBehaviour, IMenuState
{
    [SerializeField] private TextData tutorialText;
    [SerializeField] private GameObject titleTextPrefab;
    [SerializeField] private GameObject scrollArea;
    [SerializeField] private Button closeButton;


    private void Start()
    {
        closeButton.onClick.AddListener(() => gameObject.SetActive(false));

        foreach (var pair in tutorialText.TextPairs)
        {
            GameObject titleText = Instantiate(titleTextPrefab, scrollArea.transform);
            TextMeshProUGUI[] text = titleText.GetComponentsInChildren<TextMeshProUGUI>();
            text[0].text = pair.Title;
            text[1].text = pair.TutorialText;
        }

        LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
    }

    public void Enter()
    {
        gameObject.SetActive(!gameObject.activeSelf);
    }

    public void Exit()
    {
        gameObject.SetActive(false);
    }

    public void UpdateMenu() { }

}
