'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var Portal = require('../../portal/src/Portal.cjs');
require('../../transition/index.cjs');
var Notice = require('./Notice.cjs');
var transition = require('../../transition/src/transition.cjs');
var _class = require('../../../utils/dom/class.cjs');

let seed = 0;
const now = Date.now();
function getUuid() {
  const id = seed;
  seed += 1;
  return `rcNotification_${now}_${id}`;
}
const Notification = /* @__PURE__ */ vue.defineComponent({
  name: "HookNotification",
  inheritAttrs: false,
  props: ["prefixCls", "transitionName", "animation", "maxCount", "closeIcon", "hashId", "remove", "notices", "getStyles", "getClassName", "onAllRemoved", "getContainer"],
  setup(props, {
    attrs,
    slots
  }) {
    const hookRefs = /* @__PURE__ */ new Map();
    const notices = vue.computed(() => props.notices);
    const transitionProps = vue.computed(() => {
      let name = props.transitionName;
      if (!name && props.animation) {
        switch (typeof props.animation) {
          case "string":
            name = props.animation;
            break;
          case "function":
            name = props.animation().name;
            break;
          case "object":
            name = props.animation.name;
            break;
          default:
            name = `${props.prefixCls}-fade`;
            break;
        }
      }
      return transition.getTransitionGroupProps(name);
    });
    const remove = (key) => props.remove(key);
    const placements = vue.ref({});
    vue.watch(notices, () => {
      const nextPlacements = {};
      Object.keys(placements.value).forEach((placement) => {
        nextPlacements[placement] = [];
      });
      props.notices.forEach((config) => {
        const {
          placement = "topRight"
        } = config.notice;
        if (placement) {
          nextPlacements[placement] = nextPlacements[placement] || [];
          nextPlacements[placement].push(config);
        }
      });
      placements.value = nextPlacements;
    });
    const placementList = vue.computed(() => Object.keys(placements.value));
    return () => {
      var _a;
      const {
        prefixCls,
        closeIcon = (_a = slots.closeIcon) == null ? void 0 : _a.call(slots, {
          prefixCls
        })
      } = props;
      const noticeNodes = placementList.value.map((placement) => {
        var _a2, _b;
        const noticesForPlacement = placements.value[placement];
        const classes = (_a2 = props.getClassName) == null ? void 0 : _a2.call(props, placement);
        const styles = (_b = props.getStyles) == null ? void 0 : _b.call(props, placement);
        const noticeNodesForPlacement = noticesForPlacement.map(({
          notice,
          holderCallback
        }, index) => {
          const updateMark = index === notices.value.length - 1 ? notice.updateMark : void 0;
          const {
            key,
            userPassKey
          } = notice;
          const {
            content
          } = notice;
          const noticeProps = {
            prefixCls,
            closeIcon: typeof closeIcon === "function" ? closeIcon({
              prefixCls
            }) : closeIcon,
            ...notice,
            ...notice.props,
            key,
            noticeKey: userPassKey || key,
            updateMark,
            onClose: (noticeKey) => {
              var _a3;
              remove(noticeKey);
              (_a3 = notice.onClose) == null ? void 0 : _a3.call(notice);
            },
            onClick: notice.onClick
          };
          if (holderCallback) {
            return vue.createVNode("div", {
              "key": key,
              "class": `${prefixCls}-hook-holder`,
              "ref": (div) => {
                if (typeof key === "undefined")
                  return;
                if (div) {
                  hookRefs.set(key, div);
                  holderCallback(div, noticeProps);
                } else {
                  hookRefs.delete(key);
                }
              }
            }, null);
          }
          return vue.createVNode(Notice.default, {
            ...noticeProps,
            "class": _class.classNames(noticeProps.class, props.hashId)
          }, {
            default: () => [typeof content === "function" ? content({
              prefixCls
            }) : content]
          });
        });
        const className = {
          [prefixCls]: 1,
          [`${prefixCls}-${placement}`]: 1,
          [attrs.class]: !!attrs.class,
          [props.hashId]: true,
          [classes]: !!classes
        };
        function onAfterLeave() {
          var _a3;
          if (noticesForPlacement.length > 0)
            return;
          Reflect.deleteProperty(placements.value, placement);
          (_a3 = props.onAllRemoved) == null ? void 0 : _a3.call(props);
        }
        return vue.createVNode("div", {
          "key": placement,
          "class": className,
          "style": attrs.style || styles || {
            top: "65px",
            left: "50%"
          }
        }, [vue.createVNode(vue.TransitionGroup, {
          "tag": "div",
          ...transitionProps.value,
          "onAfterLeave": onAfterLeave
        }, {
          default: () => [noticeNodesForPlacement]
        })]);
      });
      return vue.createVNode(Portal.default, {
        "getContainer": props.getContainer
      }, {
        default: () => [noticeNodes]
      });
    };
  }
});

exports.default = Notification;
exports.getUuid = getUuid;
//# sourceMappingURL=HookNotification.cjs.map
