import { defineComponent, createVNode, mergeProps } from 'vue';
import PropTypes from '../_util/vue-types/index.mjs';
import classNames from '../_util/classNames.mjs';
import { stringType, functionType } from '../_util/type.mjs';
import { filterEmpty } from '../_util/props-util/index.mjs';
import { cloneElement } from '../_util/vnode.mjs';
import VcStep from './Step.mjs';

var Steps = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Steps",
  props: {
    type: {
      type: String,
      default: "default"
    },
    prefixCls: {
      type: String,
      default: "vc-steps"
    },
    iconPrefix: {
      type: String,
      default: "vc"
    },
    direction: {
      type: String,
      default: "horizontal"
    },
    labelPlacement: {
      type: String,
      default: "horizontal"
    },
    status: stringType("process"),
    size: {
      type: String,
      default: ""
    },
    progressDot: PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func]).def(void 0),
    initial: {
      type: Number,
      default: 0
    },
    current: {
      type: Number,
      default: 0
    },
    items: {
      type: Array,
      default: () => []
    },
    icons: PropTypes.shape({
      finish: PropTypes.any,
      error: PropTypes.any
    }).loose,
    stepIcon: functionType(),
    isInline: PropTypes.looseBool,
    itemRender: functionType()
  },
  emits: ["change"],
  setup(props, {
    slots,
    emit
  }) {
    const onStepClick = (next) => {
      const {
        current
      } = props;
      if (current !== next)
        emit("change", next);
    };
    const renderStep = (item, index, legacyRender) => {
      const {
        prefixCls,
        iconPrefix,
        status,
        current,
        initial,
        icons,
        stepIcon = slots.stepIcon,
        isInline,
        itemRender,
        progressDot = slots.progressDot
      } = props;
      const mergedProgressDot = isInline || progressDot;
      const mergedItem = {
        ...item,
        class: ""
      };
      const stepNumber = initial + index;
      const commonProps = {
        active: stepNumber === current,
        stepNumber: stepNumber + 1,
        stepIndex: stepNumber,
        key: stepNumber,
        prefixCls,
        iconPrefix,
        progressDot: mergedProgressDot,
        stepIcon,
        icons,
        onStepClick
      };
      if (status === "error" && index === current - 1)
        mergedItem.class = `${prefixCls}-next-error`;
      if (!mergedItem.status) {
        if (stepNumber === current)
          mergedItem.status = status;
        else if (stepNumber < current)
          mergedItem.status = "finish";
        else
          mergedItem.status = "wait";
      }
      if (isInline) {
        mergedItem.icon = void 0;
        mergedItem.subTitle = void 0;
      }
      if (legacyRender)
        return legacyRender({
          ...mergedItem,
          ...commonProps
        });
      if (itemRender)
        mergedItem.itemRender = (stepItem) => itemRender(mergedItem, stepItem);
      return createVNode(VcStep, mergeProps(mergedItem, commonProps, {
        "__legacy": false
      }), null);
    };
    const renderStepWithNode = (node, index) => {
      return renderStep({
        ...node.props
      }, index, (stepProps) => {
        const stepNode = cloneElement(node, stepProps);
        return stepNode;
      });
    };
    return () => {
      var _a;
      const {
        prefixCls,
        direction,
        type,
        labelPlacement,
        iconPrefix,
        status,
        size,
        current,
        progressDot = slots.progressDot,
        initial,
        icons,
        items,
        isInline,
        itemRender,
        ...restProps
      } = props;
      const isNav = type === "navigation";
      const mergedProgressDot = isInline || progressDot;
      const mergedDirection = isInline ? "horizontal" : direction;
      const mergedSize = isInline ? void 0 : size;
      const adjustedLabelPlacement = mergedProgressDot ? "vertical" : labelPlacement;
      const classString = classNames(prefixCls, `${prefixCls}-${direction}`, {
        [`${prefixCls}-${mergedSize}`]: mergedSize,
        [`${prefixCls}-label-${adjustedLabelPlacement}`]: mergedDirection === "horizontal",
        [`${prefixCls}-dot`]: !!mergedProgressDot,
        [`${prefixCls}-navigation`]: isNav,
        [`${prefixCls}-inline`]: isInline
      });
      return createVNode("div", mergeProps({
        "class": classString
      }, restProps), [items.filter((item) => item).map((item, index) => renderStep(item, index)), filterEmpty((_a = slots.default) == null ? void 0 : _a.call(slots)).map(renderStepWithNode)]);
    };
  }
});

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