'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var props = require('./props.cjs');
var _class = require('../../../utils/dom/class.cjs');
var is = require('../../../utils/is.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');
var transition = require('../../../vue-components/transition/src/transition.cjs');

const iconMapFilled = {
  success: iconsVue.CheckCircleFilled,
  info: iconsVue.InfoCircleFilled,
  error: iconsVue.CloseCircleFilled,
  warning: iconsVue.ExclamationCircleFilled
};
const iconMapOutlined = {
  success: iconsVue.CheckCircleOutlined,
  info: iconsVue.InfoCircleOutlined,
  error: iconsVue.CloseCircleOutlined,
  warning: iconsVue.ExclamationCircleOutlined
};
var AAlert = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AAlert",
  inheritAttrs: false,
  props: props.alertProps(),
  setup(props, {
    slots,
    emit,
    attrs,
    expose
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject.default("alert", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    const closing = vue.shallowRef(false);
    const closed = vue.shallowRef(false);
    const alertNode = vue.shallowRef();
    const handleClose = (e) => {
      e.preventDefault();
      const dom = alertNode.value;
      dom.style.height = `${dom.offsetHeight}px`;
      dom.style.height = `${dom.offsetHeight}px`;
      closing.value = true;
      emit("close", e);
    };
    const animationEnd = () => {
      var _a;
      closing.value = false;
      closed.value = true;
      (_a = props.afterClose) == null ? void 0 : _a.call(props);
    };
    const mergedType = vue.computed(() => {
      const {
        type
      } = props;
      if (type !== void 0)
        return type;
      return props.banner ? "warning" : "info";
    });
    expose({
      animationEnd
    });
    const motionStyle = vue.shallowRef({});
    return () => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
      const {
        banner,
        closeIcon: customCloseIcon = (_a = slots.closeIcon) == null ? void 0 : _a.call(slots)
      } = props;
      let {
        closable,
        showIcon
      } = props;
      const closeText = (_c = props.closeText) != null ? _c : (_b = slots.closeText) == null ? void 0 : _b.call(slots);
      const description = (_e = props.description) != null ? _e : (_d = slots.description) == null ? void 0 : _d.call(slots);
      const message = (_g = props.message) != null ? _g : (_f = slots.message) == null ? void 0 : _f.call(slots);
      const icon = (_i = props.icon) != null ? _i : (_h = slots.icon) == null ? void 0 : _h.call(slots);
      const action = (_j = slots.action) == null ? void 0 : _j.call(slots);
      showIcon = banner && showIcon === void 0 ? true : showIcon;
      const IconType = (description ? iconMapOutlined : iconMapFilled)[mergedType.value] || null;
      if (closeText)
        closable = true;
      const prefixClsValue = prefixCls.value;
      const alertCls = _class.classNames(prefixClsValue, {
        [`${prefixClsValue}-${mergedType.value}`]: true,
        [`${prefixClsValue}-closing`]: closing.value,
        [`${prefixClsValue}-with-description`]: !!description,
        [`${prefixClsValue}-no-icon`]: !showIcon,
        [`${prefixClsValue}-banner`]: !!banner,
        [`${prefixClsValue}-closable`]: closable,
        [`${prefixClsValue}-rtl`]: direction.value === "rtl",
        [hashId.value]: true
      });
      const closeIcon = closable ? vue.createVNode("button", {
        "type": "button",
        "onClick": handleClose,
        "class": `${prefixClsValue}-close-icon`,
        "tabindex": 0
      }, [closeText ? vue.createVNode("span", {
        "class": `${prefixClsValue}-close-text`
      }, [closeText]) : customCloseIcon === void 0 ? vue.createVNode(iconsVue.CloseOutlined, null, null) : customCloseIcon]) : null;
      const iconNode = icon && (is.isValidElement(icon) ? vnode.cloneElement(icon, {
        class: `${prefixClsValue}-icon`
      }) : vue.createVNode("span", {
        "class": `${prefixClsValue}-icon`
      }, [icon])) || vue.createVNode(IconType, {
        "class": `${prefixClsValue}-icon`
      }, null);
      const transitionProps = transition.getTransitionProps(`${prefixClsValue}-motion`, {
        appear: false,
        css: true,
        onAfterLeave: animationEnd,
        onBeforeLeave: (node) => {
          node.style.maxHeight = `${node.offsetHeight}px`;
        },
        onLeave: (node) => {
          node.style.maxHeight = "0px";
        }
      });
      return wrapSSR(closed.value ? null : vue.createVNode(vue.Transition, transitionProps, {
        default: () => [vue.withDirectives(vue.createVNode("div", {
          "role": "alert",
          ...attrs,
          "style": [attrs.style, motionStyle.value],
          "class": [attrs.class, alertCls],
          "data-show": !closing.value,
          "ref": alertNode
        }, [showIcon ? iconNode : null, vue.createVNode("div", {
          "class": `${prefixClsValue}-content`
        }, [message ? vue.createVNode("div", {
          "class": `${prefixClsValue}-message`
        }, [message]) : null, description ? vue.createVNode("div", {
          "class": `${prefixClsValue}-description`
        }, [description]) : null]), action ? vue.createVNode("div", {
          "class": `${prefixClsValue}-action`
        }, [action]) : null, closeIcon]), [[vue.vShow, !closing.value]])]
      }));
    };
  }
});

exports.default = AAlert;
//# sourceMappingURL=Alert.cjs.map
