'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var TimelineItem = require('./TimelineItem.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var _class = require('../../../utils/dom/class.cjs');

var ATimeline = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATimeline",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.timelineProps(), {
    reverse: false,
    mode: ""
  }),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject.default("timeline", props);
    const [wrapSSR, hashId] = index.default(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 = props$1.filterEmpty((_c = slots.default) == null ? void 0 : _c.call(slots));
      const pendingItem = pending ? vue.createVNode(TimelineItem.default, {
        "pending": !!pending,
        "dot": pendingDot || vue.createVNode(iconsVue.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 vue.cloneVNode(ele, {
          class: _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 = _class.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(vue.createVNode("ul", {
        ...attrs,
        "class": classString
      }, [items]));
    };
  }
});

exports.default = ATimeline;
//# sourceMappingURL=Timeline.cjs.map
