using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; 

class UserInterface : MonoBehaviour
{

    public static UserInterface Instance;

    public GameObject InteractivleInfoPanel;
    public SacrificeMenu SacrificeMenu;
    public RectTransform MessagePanel;
    public Text MessageText;

    private Coroutine currentDisplayMessage; 

    public void Awake()
    {
        Instance = this;

        SetShowInteractible(false);
        SetShowSacrificeMenu(null); 
    }

    private IEnumerator displayMessageCoroutine(string message, float width, float duration)
    {
        Debug.Log("DisplayMessage"); 
        MessagePanel.gameObject.SetActive(true);
        MessagePanel.sizeDelta = new Vector2(width, MessagePanel.sizeDelta.y);
        MessageText.text = message;
        yield return new WaitForSeconds(duration);
        MessagePanel.gameObject.SetActive(false);
        MessageText.text = ""; 
    }

    public void DisplayMessage(string message, float width, float duration)
    {
        if(currentDisplayMessage != null)
        {
            StopCoroutine(currentDisplayMessage); 
        }
        currentDisplayMessage = StartCoroutine(displayMessageCoroutine(message, width, duration)); 
    }

    public void SetShowInteractible(bool show)
    {
        InteractivleInfoPanel.SetActive(show); 
    }

    public void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            SetShowSacrificeMenu(null); 
        }
    }

    public void SetShowSacrificeMenu(PressurePlate p) 
    {
        if(p == null)
        {
            SacrificeMenu.gameObject.SetActive(false); 
        }
        else
        {
            this.SacrificeMenu.PressurePlate = p;
            this.SacrificeMenu.gameObject.SetActive(true);
        }
    }
}
