/**
 * ldesign v0.2.3
 * (c) 2022年9月24日 swimly
 * @license MIT
 */

import Vue from 'vue';
import NotificationList from './list.js';
import { getAttach } from '../../utils/dom.js';
import './notification.js';
import 'lodash/isFunction';
import '@ldesign/icons-vue';
import '../../utils/render-node.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import './props.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-b1584b65.js';
import '../../utils/mixins.js';
import './const.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.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 NotifyPlugin = NotificationPlugin;

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