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

public class ConfirmationDialog : MonoBehaviour, IGUIStateable {
    #region GUIStateable
    public void GUISet(GUIStateMachine.Setting setting) {
        if (setting == GUIStateMachine.Setting.OFF) { background.SetActive(false); }
    }
    #endregion

    GameObject background;
    Text text;
    Action onConfirm;
    Action onCancel;
    GUIStateMachine gui;

    void Start () {
        background = transform.Find("Background").gameObject;
        text = background.transform.Find("Query Text").GetComponent<Text>();
        gui = FindObjectOfType<GUIStateMachine>();
        background.SetActive(false);
    }

    public void OnConfirm() {
        onConfirm();
        background.SetActive(false);
    }

    public void OnCancel() {
        onCancel();
        background.SetActive(false);
    }

    public void PostQuery(string query, Action confirm, Action cancel) {
        gui.SetState(GUIStateMachine.GUIState.CONFIRM);
        text.text = query;
        onConfirm = confirm;
        onCancel = cancel;
        background.SetActive(true);
    }
}
