using System;
using UnityEngine;
using UnityEngine.UI;

namespace Game
{
	public class TextChoiceButton : MonoBehaviour
	{
		public const float FadeInDuration = 0.5f;
		
		[SerializeField] private Text text;
		[SerializeField] private Button button;
		[SerializeField] private CanvasGroup canvasGroup;
		
		public event Action<TextChoiceButton> Clicked;

		private void Awake()
		{
			button.onClick.AddListener(Click);
			canvasGroup.alpha = 0;
		}

		private void Click()
		{
			Clicked?.Invoke(this);
		}

		public void Activate(string choiceText, Color color)
		{
			text.text = choiceText;
			text.color = color;
			button.interactable = true;
			LeanTween.cancel(canvasGroup.gameObject);
			canvasGroup.LeanAlpha(1f, FadeInDuration);
		}
		
		public void Deactivate(float duration)
		{
			button.interactable = false;
			LeanTween.cancel(canvasGroup.gameObject);
			canvasGroup.LeanAlpha(0, duration);
		}
	}
}