import { defineComponent, computed, ref, watch, createVNode, Transition, mergeProps, withDirectives, TransitionGroup, vShow } from 'vue';
import { getTransitionGroupProps, getTransitionProps } from '../_util/components/transition.mjs';
import collapseMotion from '../_util/components/collapseMotion.mjs';
import useStyle from './style/index.mjs';
import { useInjectFormItemPrefix } from './context.mjs';

var ErrorList = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ErrorList",
  inheritAttrs: false,
  props: ["errors", "help", "onErrorVisibleChanged", "helpStatus", "warnings"],
  setup(props, {
    attrs
  }) {
    const {
      prefixCls,
      status
    } = useInjectFormItemPrefix();
    const baseClassName = computed(() => `${prefixCls.value}-item-explain`);
    const visible = computed(() => !!(props.errors && props.errors.length));
    const innerStatus = ref(status.value);
    const [, hashId] = useStyle(prefixCls);
    watch([visible, status], () => {
      if (visible.value)
        innerStatus.value = status.value;
    });
    return () => {
      const colMItem = collapseMotion(`${prefixCls.value}-show-help-item`);
      const transitionGroupProps = getTransitionGroupProps(`${prefixCls.value}-show-help-item`, colMItem);
      transitionGroupProps.role = "alert";
      transitionGroupProps.class = [hashId.value, baseClassName.value, attrs.class, `${prefixCls.value}-show-help`];
      return createVNode(Transition, mergeProps(getTransitionProps(`${prefixCls.value}-show-help`), {
        "onAfterEnter": () => props.onErrorVisibleChanged(true),
        "onAfterLeave": () => props.onErrorVisibleChanged(false)
      }), {
        default: () => {
          var _a;
          return [withDirectives(createVNode(TransitionGroup, mergeProps(transitionGroupProps, {
            "tag": "div"
          }), {
            default: () => {
              var _a2;
              return [(_a2 = props.errors) == null ? void 0 : _a2.map((error, index) => createVNode("div", {
                "key": index,
                "class": innerStatus.value ? `${baseClassName.value}-${innerStatus.value}` : ""
              }, [error]))];
            }
          }), [[vShow, !!((_a = props.errors) == null ? void 0 : _a.length)]])];
        }
      });
    };
  }
});

export { ErrorList as default };
//# sourceMappingURL=ErrorList.mjs.map
