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

[RequireComponent(typeof(CanvasGroup))]
public class MessageDialog : MonoBehaviour
{
    public Text titleTxt;
    public Text messageTxt;
    public Button actionBtn;

    public bool showing => GetComponent<CanvasGroup>().blocksRaycasts;

    void Start()
    {
        MessageDialogInstance.messageDialog = this;
        actionBtn.onClick.AddListener(OnAction);
        SetActive(false);
    }

    void OnAction(){
        if(showing){
            SetActive(false);
        }
    }

    public void ShowDialog(string title, string message){
        titleTxt.text = title;
        messageTxt.text = message;

        SetActive(true);
    }

    public void SetActive(bool value){
        GetComponent<CanvasGroup>().blocksRaycasts= value;
        GetComponent<CanvasGroup>().interactable= value;
        GetComponent<CanvasGroup>().alpha= (value) ? 1: 0;
    }
}

public static class MessageDialogInstance{
    public static MessageDialog messageDialog;
}
