using Animations;
using TMPro;
using UnityEngine;

namespace Game
{
	public class TextInfoModule : MonoBehaviour
	{
		[SerializeField] private ScreenController screenController;
		[SerializeField] private TextMeshPro text;

		private void Awake()
		{
			text.alpha = 0;
		}

		public void Activate(Color color)
		{
			gameObject.SetActive(true);
			text.SetText(screenController.CurrentScreen.TextInfo);
			text.color = color;
			text.alpha = 0;
			text.TextFade(1f, ScreenController.FadeInDuration);
		}

		public void Deactivate()
		{
			if (!gameObject.activeSelf)
				return;
			
			text.TextFade(0, ScreenController.FadeOutDuration);
			CancelInvoke();
			Invoke(nameof(DeactivateGameObject), ScreenController.FadeOutDuration);
		}

		private void DeactivateGameObject()
		{
			gameObject.SetActive(false);
		}
	}
}