/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var utils_dom = require('../utils/dom.js');
var dialog_dialog = require('./dialog.js');
require('../_chunks/dep-f4db2590.js');
require('lodash/isString');
require('lodash/isFunction');
require('lodash/isArray');
require('../utils/easing.js');
require('@ldesign/icons-vue-next');
require('../hooks/useGlobalIcon.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('dayjs');
require('../hooks/useConfig.js');
require('../hooks/tnode.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('../hooks/useDestroyOnClose.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../hooks/useTeleport.js');
require('./stack.js');
require('./hooks.js');
require('lodash/omit');
require('../button/index.js');
require('../utils/withInstall.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../loading/loading.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../form/hooks.js');
require('../button/props.js');
require('./props.js');

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

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var createDialog = function createDialog(props) {
  var options = _objectSpread({}, props);
  var wrapper = document.createElement("div");
  var visible = vue.ref(false);
  var className = options.className,
    style = options.style;
  var component = vue.defineComponent({
    setup: function setup(props2, _ref) {
      var expose = _ref.expose;
      var dialogOptions = vue.ref(options);
      vue.onMounted(function () {
        visible.value = true;
        document.activeElement.blur();
      });
      var update = function update(newOptions) {
        dialogOptions.value = _objectSpread(_objectSpread({}, options), newOptions);
      };
      expose({
        update: update
      });
      return function () {
        var onClose = options.onClose || function () {
          visible.value = false;
        };
        delete options.className;
        delete options.style;
        return vue.h(dialog_dialog["default"], _objectSpread({
          onClose: onClose,
          visible: visible.value
        }, dialogOptions.value));
      };
    }
  });
  var dialog = vue.createApp(component).mount(wrapper);
  var preClassName = className;
  var updateClassNameStyle = function updateClassNameStyle(className2, style2) {
    if (className2) {
      var _wrapper$firstElement;
      if (preClassName !== className2) (_wrapper$firstElement = wrapper.firstElementChild.classList).remove.apply(_wrapper$firstElement, _toConsumableArray__default["default"](preClassName.split(" ").map(function (name) {
        return name.trim();
      })));
      className2.split(" ").forEach(function (name) {
        wrapper.firstElementChild.classList.add(name.trim());
      });
    }
    if (style2) wrapper.firstElementChild.style.cssText += style2;
    preClassName = className2;
  };
  updateClassNameStyle(className, style);
  var container = utils_dom.getAttach(options.attach);
  if (container) container.appendChild(wrapper);else console.error("attach is not exist");
  var dialogNode = {
    show: function show() {
      visible.value = true;
    },
    hide: function hide() {
      visible.value = false;
    },
    update: function update(newOptions) {
      dialog.update(newOptions);
      updateClassNameStyle(newOptions.className, newOptions.style);
    },
    destroy: function destroy() {
      visible.value = false;
      setTimeout(function () {
        wrapper.parentNode.removeChild(wrapper);
      }, 300);
    }
  };
  return dialogNode;
};
var confirm = function confirm(props) {
  return createDialog(props);
};
var alert = function alert(props) {
  var options = _objectSpread({}, props);
  options.cancelBtn = null;
  return createDialog(options);
};
var extraApi = {
  confirm: confirm,
  alert: alert
};
var DialogPlugin = createDialog;
DialogPlugin.install = function (app) {
  app.config.globalProperties.$dialog = createDialog;
  Object.keys(extraApi).forEach(function (funcName) {
    app.config.globalProperties.$dialog[funcName] = extraApi[funcName];
  });
};
Object.keys(extraApi).forEach(function (funcName) {
  DialogPlugin[funcName] = extraApi[funcName];
});

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