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

import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { getAttach } from '../utils/dom.js';
import { MessageList, DEFAULT_Z_INDEX } from './messageList.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-2cb61c79.js';
import 'dayjs';
import '../utils/mixins.js';
import './const.js';
import './message.js';
import '@ldesign/icons-vue';
import '../loading/index.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import '../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../loading/loading.js';
import '../utils/render-tnode.js';
import '@vue/composition-api';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/transfer-dom.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 '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import './animation.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 instanceMap = /* @__PURE__ */new Map();
var defaultMessageOptions = {
  duration: 3e3,
  attach: "body",
  zIndex: DEFAULT_Z_INDEX,
  placement: "top"
};
function handleParams(params) {
  var options = _objectSpread(_objectSpread({}, defaultMessageOptions), params);
  options.content = params.content;
  return options;
}
var MessageFunction = function MessageFunction(props) {
  var options = handleParams(props);
  var attach = options.attach,
    placement = options.placement;
  var attachDom = getAttach(attach);
  if (!instanceMap.get(attachDom)) instanceMap.set(attachDom, {});
  var p = instanceMap.get(attachDom)[placement];
  if (!p) {
    var instance = new MessageList({
      propsData: {
        zIndex: options.zIndex,
        placement: options.placement
      }
    }).$mount();
    instance.add(options);
    instanceMap.get(attachDom)[placement] = instance;
    attachDom.appendChild(instance.$el);
  } else {
    p.add(options);
  }
  return new Promise(function (resolve) {
    var ins = instanceMap.get(attachDom)[placement];
    ins.$nextTick(function () {
      var msg = ins.$children;
      resolve(msg[msg.length - 1]);
    });
  });
};
var showThemeMessage = function showThemeMessage(theme, params, duration) {
  var options = {
    theme: theme
  };
  if (typeof params === "string") options.content = params;else if (_typeof(params) === "object" && !Array.isArray(params)) options = _objectSpread(_objectSpread({}, options), params);
  (duration || duration === 0) && (options.duration = duration);
  return MessageFunction(options);
};
var setMessageConfig = function setMessageConfig(_ref) {
  var placement = _ref.placement,
    attach = _ref.attach,
    offset = _ref.offset,
    zIndex = _ref.zIndex;
  attach && (defaultMessageOptions.attach = attach);
  offset && (defaultMessageOptions.offset = offset);
  placement && (defaultMessageOptions.placement = placement);
  zIndex && (defaultMessageOptions.zIndex = zIndex);
};
var extraApi = {
  info: function info(params, duration) {
    return showThemeMessage("info", params, duration);
  },
  success: function success(params, duration) {
    return showThemeMessage("success", params, duration);
  },
  warning: function warning(params, duration) {
    return showThemeMessage("warning", params, duration);
  },
  error: function error(params, duration) {
    return showThemeMessage("error", params, duration);
  },
  question: function question(params, duration) {
    return showThemeMessage("question", params, duration);
  },
  loading: function loading(params, duration) {
    return showThemeMessage("loading", params, duration);
  },
  close: function close(promise) {
    promise.then(function (instance) {
      return instance.close();
    });
  },
  closeAll: function closeAll() {
    if (instanceMap instanceof Map) {
      instanceMap.forEach(function (attach) {
        Object.keys(attach).forEach(function (placement) {
          var instance = attach[placement];
          instance.list = [];
        });
      });
    }
  },
  config: setMessageConfig
};
var MessagePlugin = showThemeMessage;
Object.keys(extraApi).forEach(function (funcName) {
  MessagePlugin[funcName] = extraApi[funcName];
});
MessagePlugin.install = function () {
  Vue.prototype.$message = MessagePlugin;
};
var message = MessagePlugin;

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