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

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { ref, defineComponent, onMounted, h, createApp } from 'vue';
import { getAttach } from '../utils/dom.js';
import _Dialog from './dialog.js';
import '../_chunks/dep-2e5d8948.js';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isArray';
import '../utils/easing.js';
import '@ldesign/icons-vue-next';
import '../hooks/useGlobalIcon.js';
import '../hooks/useConfig.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../_chunks/dep-4580aabe.js';
import '../config-provider/type.js';
import '../hooks/tnode.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import '../hooks/useDestroyOnClose.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../hooks/useTeleport.js';
import './stack.js';
import './hooks.js';
import 'lodash/omit';
import '../button/index.js';
import '../utils/withInstall.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../loading/loading.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../loading/style';
import '../loading/type.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useKeepAnimation.js';
import '../form/hooks.js';
import '../button/props.js';
import '../button/style';
import '../button/type.js';
import './props.js';

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(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 = ref(false);
  var className = options.className,
    style = options.style;
  var component = defineComponent({
    setup: function setup(props2, _ref) {
      var expose = _ref.expose;
      var dialogOptions = ref(options);
      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 h(_Dialog, _objectSpread({
          onClose: onClose,
          visible: visible.value
        }, dialogOptions.value));
      };
    }
  });
  var dialog = 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(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 = 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];
});

export { DialogPlugin, DialogPlugin as default };
//# sourceMappingURL=plugin.js.map
