"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Vue = require("vue");
const mountComponent = require("../utils/mount-component.js");
const Notify = require("./Notify.js");
const basic = require("../utils/basic.js");
let timer;
let instance;
const parseOptions = (message) => basic.isObject(message) ? message : {
  message
};
function initInstance() {
  ({
    instance
  } = mountComponent.mountComponent({
    setup() {
      const {
        state,
        toggle
      } = mountComponent.usePopupState();
      return () => Vue.createVNode(Notify.default, Vue.mergeProps(state, {
        "onUpdate:show": toggle
      }), null);
    }
  }));
}
const getDefaultOptions = () => ({
  type: "danger",
  color: void 0,
  message: "",
  onClose: void 0,
  onClick: void 0,
  onOpened: void 0,
  duration: 3e3,
  position: void 0,
  className: "",
  lockScroll: false,
  background: void 0
});
let currentOptions = getDefaultOptions();
const closeNotify = () => {
  if (instance) {
    instance.toggle(false);
  }
};
function showNotify(options) {
  if (!basic.inBrowser) {
    return;
  }
  if (!instance) {
    initInstance();
  }
  options = basic.extend({}, currentOptions, parseOptions(options));
  instance.open(options);
  clearTimeout(timer);
  if (options.duration > 0) {
    timer = setTimeout(closeNotify, options.duration);
  }
  return instance;
}
exports.closeNotify = closeNotify;
exports.showNotify = showNotify;
