import { defineComponent, computed, shallowRef, createVNode } from 'vue';
import '../../../utils/index.mjs';
import useNotification$1 from '../../../vue-components/vc-notification/src/useNotification.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import useStyle from '../style/index.mjs';
import { getPlacementStyle, getMotion } from './util.mjs';
import { getCloseIcon, PureContent } from './PurePanel.mjs';
import { classNames } from '../../../utils/dom/class.mjs';

const DEFAULT_OFFSET = 24;
const DEFAULT_DURATION = 4.5;
const Holder = /* @__PURE__ */ defineComponent({
  name: "Holder",
  inheritAttrs: false,
  props: ["prefixCls", "class", "type", "icon", "content", "onAllRemoved"],
  setup(props, {
    expose
  }) {
    const {
      getPrefixCls,
      getPopupContainer
    } = useConfigInject("notification", props);
    const prefixCls = computed(() => props.prefixCls || getPrefixCls("notification"));
    const getStyles = (placement) => {
      var _a, _b;
      return getPlacementStyle(placement, (_a = props.top) != null ? _a : DEFAULT_OFFSET, (_b = props.bottom) != null ? _b : DEFAULT_OFFSET);
    };
    const [, hashId] = useStyle(prefixCls);
    const getClassName = () => classNames(hashId.value, {
      [`${prefixCls.value}-rtl`]: props.rtl
    });
    const getNotificationMotion = () => getMotion(prefixCls.value);
    const [api, holder] = useNotification$1({
      prefixCls: prefixCls.value,
      getStyles,
      getClassName,
      motion: getNotificationMotion,
      closable: true,
      closeIcon: 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 = 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: () => createVNode(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: 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, () => createVNode(Holder, {
    "key": holderKey,
    ...notificationConfig,
    "ref": holderRef
  }, null)];
}
function useNotification(notificationConfig) {
  return useInternalNotification(notificationConfig);
}

export { useNotification as default, useInternalNotification };
//# sourceMappingURL=useNotification.mjs.map
