"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Vue = require("vue");
const mountComponent = require("../utils/mount-component.js");
const Dialog = require("./Dialog.js");
const basic = require("../utils/basic.js");
let instance;
const DEFAULT_OPTIONS = {
  title: "",
  width: "",
  theme: null,
  message: "",
  overlay: true,
  callback: null,
  teleport: "body",
  className: "",
  allowHtml: false,
  lockScroll: true,
  transition: void 0,
  beforeClose: null,
  overlayClass: "",
  overlayStyle: void 0,
  messageAlign: "",
  cancelButtonText: "",
  cancelButtonColor: null,
  cancelButtonDisabled: false,
  confirmButtonText: "",
  confirmButtonColor: null,
  confirmButtonDisabled: false,
  showConfirmButton: true,
  showCancelButton: false,
  closeOnPopstate: true,
  closeOnClickOverlay: false,
  destroyOnClose: false
};
let currentOptions = basic.extend({}, DEFAULT_OPTIONS);
function initInstance() {
  const Wrapper = {
    setup() {
      const {
        state,
        toggle
      } = mountComponent.usePopupState();
      return () => Vue.createVNode(Dialog.default, Vue.mergeProps(state, {
        "onUpdate:show": toggle
      }), null);
    }
  };
  ({
    instance
  } = mountComponent.mountComponent(Wrapper));
}
function showDialog(options) {
  if (!basic.inBrowser) {
    return Promise.resolve(void 0);
  }
  return new Promise((resolve, reject) => {
    if (!instance) {
      initInstance();
    }
    instance.open(basic.extend({}, currentOptions, options, {
      callback: (action) => {
        (action === "confirm" ? resolve : reject)(action);
      }
    }));
  });
}
const showConfirmDialog = (options) => showDialog(basic.extend({
  showCancelButton: true
}, options));
const closeDialog = () => {
  if (instance) {
    instance.toggle(false);
  }
};
exports.closeDialog = closeDialog;
exports.showConfirmDialog = showConfirmDialog;
exports.showDialog = showDialog;
