import { isVNode, defineComponent, createVNode, cloneVNode, mergeProps } from 'vue';
import { LoadingOutlined } from '@ant-design/icons-vue';
import '../hooks/index.mjs';
import classNames from '../_util/classNames.mjs';
import PropTypes from '../_util/vue-types/index.mjs';
import { filterEmpty } from '../_util/props-util/index.mjs';
import initDefaultProps from '../_util/props-util/initDefaultProps.mjs';
import { booleanType, tuple } from '../_util/type.mjs';
import TimelineItem from './TimelineItem.mjs';
import useStyle from './style/index.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
const timelineProps = () => ({
  prefixCls: String,
  /** 指定最后一个幽灵节点是否存在或内容 */
  pending: PropTypes.any,
  pendingDot: PropTypes.any,
  reverse: booleanType(),
  mode: PropTypes.oneOf(tuple("left", "alternate", "right", ""))
});
var Timeline = /* @__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(TimelineItem, {
        "pending": !!pending,
        "dot": pendingDot || createVNode(LoadingOutlined, null, null)
      }, _isSlot(pendingNode) ? pendingNode : {
        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", mergeProps(attrs, {
        "class": classString
      }), [items]));
    };
  }
});

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