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

'use strict';

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

var Vue = require('vue');
var utils_dom = require('../../utils/dom.js');
var components_notification_list = require('./list.js');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('./notification.js');
require('lodash/isFunction');
require('@ldesign/icons-vue');
require('../../utils/render-node.js');
require('./props.js');
require('./const.js');

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

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

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 = utils_dom.getAttach(hackOptions.attach);
  if (!instanceMap.get(attachEl)) instanceMap.set(attachEl, {});
  let tmpInstance = instanceMap.get(attachEl)[hackOptions.placement];
  if (!tmpInstance) {
    const list = new components_notification_list["default"]({
      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__default["default"].prototype.$notify = NotificationPlugin;
  Vue__default["default"].prototype.$notification = NotificationPlugin;
};
const notify = NotificationPlugin;
const NotifyPlugin = NotificationPlugin;

exports.NotificationPlugin = NotificationPlugin;
exports.NotifyPlugin = NotifyPlugin;
exports["default"] = NotifyPlugin;
exports.notify = notify;
//# sourceMappingURL=plugin.js.map
