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

public class YesNoDilougueUI : MonoBehaviour {

    public static YesNoDilougueUI Instance { get; private set; }
    TMP_Text questionText;
    Button confirmButton;
    Button declineButton;

    private void Awake() {
        Instance = this;
        confirmButton = transform.Find("ConfirmButton").GetComponent<Button>();
        declineButton = transform.Find("DeclineButton").GetComponent<Button>();
        questionText = transform.Find("QuestionText").GetComponent<TextMeshProUGUI>();

        Hide();
        transform.localPosition = Vector3.zero;
    }

    public void SetQuestionText(String text) {
        questionText.text = text;
    }

    public void ShowDialog(string questionText, Action YesAction, Action NoAction) {
        gameObject.SetActive(true);
        SetQuestionText(questionText);
        confirmButton.onClick.AddListener(() => { Hide(); YesAction(); });

        declineButton.onClick.AddListener(() => { Hide(); NoAction(); });
    }

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