'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var useNotification$1 = require('../../../vue-components/vc-notification/src/useNotification.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var util = require('./util.cjs');
var PurePanel = require('./PurePanel.cjs');
var _class = require('../../../utils/dom/class.cjs');

const DEFAULT_OFFSET = 24;
const DEFAULT_DURATION = 4.5;
const Holder = /* @__PURE__ */ vue.defineComponent({
  name: "Holder",
  inheritAttrs: false,
  props: ["prefixCls", "class", "type", "icon", "content", "onAllRemoved"],
  setup(props, {
    expose
  }) {
    const {
      getPrefixCls,
      getPopupContainer
    } = useConfigInject.default("notification", props);
    const prefixCls = vue.computed(() => props.prefixCls || getPrefixCls("notification"));
    const getStyles = (placement) => {
      var _a, _b;
      return util.getPlacementStyle(placement, (_a = props.top) != null ? _a : DEFAULT_OFFSET, (_b = props.bottom) != null ? _b : DEFAULT_OFFSET);
    };
    const [, hashId] = index.default(prefixCls);
    const getClassName = () => _class.classNames(hashId.value, {
      [`${prefixCls.value}-rtl`]: props.rtl
    });
    const getNotificationMotion = () => util.getMotion(prefixCls.value);
    const [api, holder] = useNotification$1.default({
      prefixCls: prefixCls.value,
      getStyles,
      getClassName,
      motion: getNotificationMotion,
      closable: true,
      closeIcon: PurePanel.getCloseIcon(prefixCls.value),
      duration: DEFAULT_DURATION,
      getContainer: () => {
        var _a, _b;
        return ((_a = props.getPopupContainer) == null ? void 0 : _a.call(props)) || ((_b = getPopupContainer.value) == null ? void 0 : _b.call(getPopupContainer)) || document.body;
      },
      maxCount: props.maxCount,
      hashId: hashId.value,
      onAllRemoved: props.onAllRemoved
    });
    expose({
      ...api,
      prefixCls: prefixCls.value,
      hashId
    });
    return holder;
  }
});
function useInternalNotification(notificationConfig) {
  const holderRef = vue.shallowRef(null);
  const holderKey = Symbol("notificationHolderKey");
  const open = (config) => {
    if (!holderRef.value)
      return;
    const {
      open: originOpen,
      prefixCls,
      hashId
    } = holderRef.value;
    const noticePrefixCls = `${prefixCls}-notice`;
    const {
      message,
      description,
      icon,
      type,
      btn,
      class: className,
      ...restConfig
    } = config;
    return originOpen({
      placement: "topRight",
      ...restConfig,
      content: () => vue.createVNode(PurePanel.PureContent, {
        "prefixCls": noticePrefixCls,
        "icon": typeof icon === "function" ? icon() : icon,
        "type": type,
        "message": typeof message === "function" ? message() : message,
        "description": typeof description === "function" ? description() : description,
        "btn": typeof btn === "function" ? btn() : btn
      }, null),
      // @ts-expect-error
      class: _class.classNames(type && `${noticePrefixCls}-${type}`, hashId, className)
    });
  };
  const destroy = (key) => {
    var _a, _b;
    if (key !== void 0)
      (_a = holderRef.value) == null ? void 0 : _a.close(key);
    else
      (_b = holderRef.value) == null ? void 0 : _b.destroy();
  };
  const wrapAPI = {
    open,
    destroy
  };
  const keys = ["success", "info", "warning", "error"];
  keys.forEach((type) => {
    wrapAPI[type] = (config) => open({
      ...config,
      type
    });
  });
  return [wrapAPI, () => vue.createVNode(Holder, {
    "key": holderKey,
    ...notificationConfig,
    "ref": holderRef
  }, null)];
}
function useNotification(notificationConfig) {
  return useInternalNotification(notificationConfig);
}

exports.default = useNotification;
exports.useInternalNotification = useInternalNotification;
//# sourceMappingURL=useNotification.cjs.map
