using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;

public class Announcments : MonoBehaviour
{
	[SerializeField] TextMeshProUGUI announcementText;

	public Queue<Tuple<string, float>> announcementQueue = new Queue<Tuple<string, float>>();
	private bool workingOnQueue = false;
	private float remainingTime;

	void Update()
	{
		if (!workingOnQueue && announcementQueue.Count != 0)
		{
			workingOnQueue = true;
			Tuple<string, float> announcement = announcementQueue.Dequeue();
			AnnounceText(announcement.Item1, announcement.Item2);
			return;
		}
		if (remainingTime > 0)
		{
			remainingTime -= Time.deltaTime;
		}
		else
		{
			workingOnQueue = false;
			announcementText.enabled = false;
			remainingTime = 0;
			if (announcementQueue.Count == 0)
			{
				enabled = false;
			}
		}
	}

	public void AnnounceText(string text, float time)
	{
		announcementText.text = text;
		announcementText.enabled = true;
		remainingTime = time;
		enabled = true;
	}

	public void QueueAnnounceText(string text, float time)
	{
		announcementQueue.Enqueue(new Tuple<string, float>(text, time));
		enabled = true;
	}

	public void AnnounceText(string text)
	{
		announcementText.text = text;
		announcementText.enabled = true;
		announcementQueue.Clear();
		enabled = false;
	}

	public void StopAnnouncement()
	{
		announcementQueue.Clear();
		announcementText.text = String.Empty;
		remainingTime = 0;
		announcementText.enabled = false;
		enabled = false;
	}
}
