import { defineComponent, createVNode, cloneVNode } from 'vue';
import { LoadingOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import useStyle from '../style/index.mjs';
import ATimelineItem from './TimelineItem.mjs';
import { timelineProps } from './props.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';
import { filterEmpty } from '../../../utils/vue/props.mjs';
import { classNames } from '../../../utils/dom/class.mjs';

var ATimeline = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATimeline",
  inheritAttrs: false,
  props: initDefaultProps(timelineProps(), {
    reverse: false,
    mode: ""
  }),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject("timeline", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const getPositionCls = (ele, idx) => {
      const eleProps = ele.props || {};
      if (props.mode === "alternate") {
        if (eleProps.position === "right")
          return `${prefixCls.value}-item-right`;
        if (eleProps.position === "left")
          return `${prefixCls.value}-item-left`;
        return idx % 2 === 0 ? `${prefixCls.value}-item-left` : `${prefixCls.value}-item-right`;
      }
      if (props.mode === "left")
        return `${prefixCls.value}-item-left`;
      if (props.mode === "right")
        return `${prefixCls.value}-item-right`;
      if (eleProps.position === "right")
        return `${prefixCls.value}-item-right`;
      return "";
    };
    return () => {
      var _a, _b, _c;
      const {
        pending = (_a = slots.pending) == null ? void 0 : _a.call(slots),
        pendingDot = (_b = slots.pendingDot) == null ? void 0 : _b.call(slots),
        reverse,
        mode
      } = props;
      const pendingNode = typeof pending === "boolean" ? null : pending;
      const children = filterEmpty((_c = slots.default) == null ? void 0 : _c.call(slots));
      const pendingItem = pending ? createVNode(ATimelineItem, {
        "pending": !!pending,
        "dot": pendingDot || createVNode(LoadingOutlined, null, null)
      }, {
        default: () => [pendingNode]
      }) : null;
      if (pendingItem)
        children.push(pendingItem);
      const timeLineItems = reverse ? children.reverse() : children;
      const itemsCount = timeLineItems.length;
      const lastCls = `${prefixCls.value}-item-last`;
      const items = timeLineItems.map((ele, idx) => {
        const pendingClass = idx === itemsCount - 2 ? lastCls : "";
        const readyClass = idx === itemsCount - 1 ? lastCls : "";
        return cloneVNode(ele, {
          class: classNames([!reverse && !!pending ? pendingClass : readyClass, getPositionCls(ele, idx)])
        });
      });
      const hasLabelItem = timeLineItems.some((item) => {
        var _a2, _b2;
        return !!(((_a2 = item.props) == null ? void 0 : _a2.label) || ((_b2 = item.children) == null ? void 0 : _b2.label));
      });
      const classString = classNames(prefixCls.value, {
        [`${prefixCls.value}-pending`]: !!pending,
        [`${prefixCls.value}-reverse`]: !!reverse,
        [`${prefixCls.value}-${mode}`]: !!mode && !hasLabelItem,
        [`${prefixCls.value}-label`]: hasLabelItem,
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      }, attrs.class, hashId.value);
      return wrapSSR(createVNode("ul", {
        ...attrs,
        "class": classString
      }, [items]));
    };
  }
});

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