/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var dialog_dialog = require('./dialog.js');
var utils_dom = require('../utils/dom.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/throttle');
require('tdesign-icons-vue');
require('../config.js');
require('../button/index.js');
require('../button/button.js');
require('../_chunks/dep-99705d51.js');
require('../utils/classnames.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../button/props.js');
require('../utils/ripple.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../utils/mixins.js');
require('./actions.js');
require('lodash/isObject');
require('./props.js');
require('../utils/event.js');
require('../utils/helper.js');
require('lodash/camelCase');
require('../hooks/useDestroyOnClose.js');

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

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

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

  options.visible = true;
  var dialog = new dialog_dialog["default"]({
    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 = utils_dom.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__default["default"].prototype.$dialog = createDialog;
    Object.keys(extraApi).forEach(function (funcName) {
      Vue__default["default"].prototype.$dialog[funcName] = extraApi[funcName];
    });
  }
};
Object.keys(extraApi).forEach(function (funcName) {
  _DialogPlugin[funcName] = extraApi[funcName];
});
var DialogPlugin = _DialogPlugin;

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