/**
 * 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 NotificationList 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 './notification.js';
import 'lodash/isFunction';
import '@ldesign/icons-vue';
import '../../utils/render-node.js';
import './props.js';
import './const.js';

let seed = 0;
const instanceMap = /* @__PURE__ */new Map();
const NotificationFunction = options => {
  seed += 1;
  const hackOptions = {
    placement: "top-right",
    zIndex: 6e3,
    attach: "body",
    id: seed,
    ...options
  };
  hackOptions.content = options.content ? options.content : "";
  const attachEl = getAttach(hackOptions.attach);
  if (!instanceMap.get(attachEl)) instanceMap.set(attachEl, {});
  let tmpInstance = instanceMap.get(attachEl)[hackOptions.placement];
  if (!tmpInstance) {
    const list = new NotificationList({
      propsData: {
        placement: hackOptions.placement
      }
    });
    list.add(hackOptions);
    list.$mount();
    instanceMap.get(attachEl)[hackOptions.placement] = list;
    attachEl.appendChild(list.$el);
    tmpInstance = instanceMap.get(attachEl)[hackOptions.placement];
  } else {
    tmpInstance.add(hackOptions);
  }
  return new Promise(resolve => {
    tmpInstance.$nextTick(() => {
      const list = tmpInstance.$children;
      resolve(list[list.length - 1]);
    });
  });
};
const showThemeNotification = (theme, options) => {
  const hackOptions = {
    ...options,
    theme
  };
  return NotificationFunction(hackOptions);
};
const extraApi = {
  info: options => showThemeNotification("info", options),
  success: options => showThemeNotification("success", options),
  warning: options => showThemeNotification("warning", options),
  error: options => showThemeNotification("error", options),
  close: promise => {
    promise.then(instance => instance.close());
  },
  closeAll: () => {
    instanceMap.forEach(attach => {
      Object.keys(attach).forEach(placement => {
        attach[placement].removeAll();
      });
    });
  }
};
const NotificationPlugin = showThemeNotification;
Object.keys(extraApi).forEach(funcName => {
  NotificationPlugin[funcName] = extraApi[funcName];
});
NotificationPlugin.install = () => {
  Vue.prototype.$notify = NotificationPlugin;
  Vue.prototype.$notification = NotificationPlugin;
};
const notify = NotificationPlugin;
const NotifyPlugin = NotificationPlugin;

export { NotificationPlugin, NotifyPlugin, NotifyPlugin as default, notify };
//# sourceMappingURL=plugin.js.map
