/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import _Dialog from './dialog.js';
import { getAttach } from '../utils/dom.js';
import 'tdesign-icons-vue';
import '../config.js';
import '../button/index.js';
import '../button/button.js';
import '../utils/classnames.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../utils/set-style.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../loading/type.js';
import '../loading/plugin.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../button/type.js';
import './actions.js';
import '../_chunks/dep-42d5c87e.js';
import 'lodash/isObject';
import './props.js';
import '../utils/mixins.js';
import '../config-provider/config-receiver.js';
import '../config-provider/zh_CN_config.js';
import '../config-provider/type.js';
import '../utils/event.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';

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);

  options.visible = true;
  var dialog = new _Dialog({
    propsData: _objectSpread(_objectSpread({}, options), {}, {
      onClose: options.onClose || function () {
        dialog.visible = false;
      }
    })
  }).$mount();

  if (options.className) {
    options.className.split(" ").forEach(function (name) {
      dialog.$el.classList.add(name.trim());
    });
  }

  if (options.style) {
    dialog.$el.style.cssText += options.style;
  }

  var container = getAttach(options.attach);

  if (container) {
    container.appendChild(dialog.$el);
  } else {
    console.error("attach is not exist");
  }

  var dialogNode = {
    show: function show() {
      dialog.visible = true;
    },
    hide: function hide() {
      dialog.visible = false;
    },
    update: function update(options2) {
      Object.assign(dialog, options2);
    },
    destroy: function destroy() {
      dialog.visible = false;
      container.contains(dialog.$el) && container.removeChild(dialog.$el);
    }
  };
  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 = {
  install: function install() {
    Vue.prototype.$dialog = createDialog;
    Object.keys(extraApi).forEach(function (funcName) {
      Vue.prototype.$dialog[funcName] = extraApi[funcName];
    });
  }
};
Object.keys(extraApi).forEach(function (funcName) {
  _DialogPlugin[funcName] = extraApi[funcName];
});
var DialogPlugin = _DialogPlugin;

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