'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
require('../hooks/index.js');
var classNames = require('../_util/classNames.js');
var index = require('../_util/vue-types/index.js');
var index$2 = require('../_util/props-util/index.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var type = require('../_util/type.js');
var TimelineItem = require('./TimelineItem.js');
var index$1 = require('./style/index.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
const timelineProps = () => ({
  prefixCls: String,
  /** 指定最后一个幽灵节点是否存在或内容 */
  pending: index.default.any,
  pendingDot: index.default.any,
  reverse: type.booleanType(),
  mode: index.default.oneOf(type.tuple("left", "alternate", "right", ""))
});
var Timeline = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATimeline",
  inheritAttrs: false,
  props: initDefaultProps.default(timelineProps(), {
    reverse: false,
    mode: ""
  }),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject.default("timeline", props);
    const [wrapSSR, hashId] = index$1.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 = index$2.filterEmpty((_c = slots.default) == null ? void 0 : _c.call(slots));
      const pendingItem = pending ? vue.createVNode(TimelineItem.default, {
        "pending": !!pending,
        "dot": pendingDot || vue.createVNode(CloseOutlined.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 vue.cloneVNode(ele, {
          class: classNames.default([!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.default(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", vue.mergeProps(attrs, {
        "class": classString
      }), [items]));
    };
  }
});

exports.default = Timeline;
exports.timelineProps = timelineProps;
//# sourceMappingURL=Timeline.js.map
