/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var Vue = require('vue');
var log = require('../../chunks/log.js');
var utils_dom = require('../../utils/dom.js');
var components_dialog_dialog = require('./dialog.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('lodash/isNumber');
require('lodash/throttle');
require('@ldesign/icons-vue');
require('../button/index.js');
require('../../utils/with-install.js');
require('lodash');
require('../../config.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../../utils/render-node.js');
require('../../utils/transfer-dom.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../../chunks/defineProperty-838e4192.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../loading/plugin.js');
require('../../utils/ripple.js');
require('../button/props.js');
require('../../utils/event.js');
require('../../utils/helper.js');
require('lodash/camelCase');
require('../../hooks/use-destroy-onclose.js');
require('./props.js');
require('./mixins/action.js');
require('../../chunks/helper.js');
require('lodash/isObject');
require('./stack.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

const createDialog = props => {
  const options = {
    ...props
  };
  const dialog = new components_dialog_dialog["default"]({
    propsData: {
      ...options,
      onClose: options.onClose || (() => {
        dialog.visible = false;
      })
    }
  }).$mount();
  dialog.visible = true;
  if (options.className) {
    options.className.split(" ").forEach(name => {
      dialog.$el.classList.add(name.trim());
    });
  }
  if (options.style) dialog.$el.style.cssText += options.style;
  const container = utils_dom.getAttach(options.attach);
  if (container) container.appendChild(dialog.$el);else log.log.error("DialogPlugin", "attach is not exist");
  const dialogNode = {
    show: () => {
      dialog.visible = true;
    },
    hide: () => {
      dialog.visible = false;
    },
    update: options2 => {
      Object.assign(dialog, options2);
    },
    destroy: () => {
      dialog.visible = false;
      container.contains(dialog.$el) && container.removeChild(dialog.$el);
    }
  };
  return dialogNode;
};
const confirm = props => createDialog(props);
const alert = props => {
  const options = {
    ...props
  };
  options.cancelBtn = null;
  return createDialog(options);
};
const extraApi = {
  confirm,
  alert
};
const _DialogPlugin = {
  install: () => {
    Vue__default["default"].prototype.$dialog = createDialog;
    Object.keys(extraApi).forEach(funcName => {
      Vue__default["default"].prototype.$dialog[funcName] = extraApi[funcName];
    });
  }
};
Object.keys(extraApi).forEach(funcName => {
  _DialogPlugin[funcName] = extraApi[funcName];
});
const DialogPlugin = _DialogPlugin;

exports.DialogPlugin = DialogPlugin;
exports["default"] = DialogPlugin;
//# sourceMappingURL=plugin.js.map
