/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import Vue from 'vue';
import { getAttach } from '../../utils/dom.js';
import { MessageList, DEFAULT_Z_INDEX } from './list.js';
import 'raf';
import 'lodash/isString';
import '../../_chunks/dep-70c789e5.js';
import '../../_chunks/dep-5210251b.js';
import '../../utils/easing.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';
import '../../utils/mixins.js';
import './const.js';
import './message.js';
import '@ldesign/icons-vue';
import '../loading/index.js';
import '../../utils/with-install.js';
import '../../config.js';
import '../loading/loading.js';
import '../../utils/render-node.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../_chunks/dep-eb467ddf.js';
import '../../_chunks/dep-cf772670.js';
import '../../_chunks/dep-47d77fc8.js';
import '../loading/plugin.js';
import './animation.js';
import './props.js';

const instanceMap = /* @__PURE__ */new Map();
const defaultMessageOptions = {
  duration: 3e3,
  attach: "body",
  zIndex: DEFAULT_Z_INDEX,
  placement: "top"
};
function handleParams(params) {
  const options = {
    ...defaultMessageOptions,
    ...params
  };
  options.content = params.content;
  return options;
}
const MessageFunction = props => {
  const options = handleParams(props);
  const {
    attach,
    placement
  } = options;
  const attachDom = getAttach(attach);
  if (!instanceMap.get(attachDom)) instanceMap.set(attachDom, {});
  const p = instanceMap.get(attachDom)[placement];
  if (!p) {
    const 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(resolve => {
    const ins = instanceMap.get(attachDom)[placement];
    ins.$nextTick(() => {
      const msg = ins.$children;
      resolve(msg[msg.length - 1]);
    });
  });
};
const showThemeMessage = (theme, params, duration) => {
  let options = {
    theme
  };
  if (typeof params === "string") options.content = params;else if (typeof params === "object" && !Array.isArray(params)) options = {
    ...options,
    ...params
  };
  (duration || duration === 0) && (options.duration = duration);
  return MessageFunction(options);
};
const setMessageConfig = _ref => {
  let {
    placement,
    attach,
    offset,
    zIndex
  } = _ref;
  attach && (defaultMessageOptions.attach = attach);
  offset && (defaultMessageOptions.offset = offset);
  placement && (defaultMessageOptions.placement = placement);
  zIndex && (defaultMessageOptions.zIndex = zIndex);
};
const extraApi = {
  info: (params, duration) => showThemeMessage("info", params, duration),
  success: (params, duration) => showThemeMessage("success", params, duration),
  warning: (params, duration) => showThemeMessage("warning", params, duration),
  error: (params, duration) => showThemeMessage("error", params, duration),
  question: (params, duration) => showThemeMessage("question", params, duration),
  loading: (params, duration) => showThemeMessage("loading", params, duration),
  close: promise => {
    promise.then(instance => instance.close());
  },
  closeAll: () => {
    if (instanceMap instanceof Map) {
      instanceMap.forEach(attach => {
        Object.keys(attach).forEach(placement => {
          const instance = attach[placement];
          instance.list = [];
        });
      });
    }
  },
  config: setMessageConfig
};
const MessagePlugin = showThemeMessage;
Object.keys(extraApi).forEach(funcName => {
  MessagePlugin[funcName] = extraApi[funcName];
});
MessagePlugin.install = () => {
  Vue.prototype.$message = MessagePlugin;
};
const message = MessagePlugin;

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