import { defineComponent, createVNode } from 'vue';
import '../../../utils/index.mjs';
import VcStep from './Step.mjs';
import PropTypes from '../../../utils/vue/vueTypes.mjs';
import { stringType, functionType } from '../../../utils/vue/propType.mjs';
import { cloneElement } from '../../../utils/vue/vnode.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import { filterEmpty } from '../../../utils/vue/props.mjs';

var VcSteps = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Steps",
  props: {
    type: PropTypes.string.def("default"),
    prefixCls: PropTypes.string.def("vc-steps"),
    iconPrefix: PropTypes.string.def("vc"),
    direction: PropTypes.string.def("horizontal"),
    labelPlacement: PropTypes.string.def("horizontal"),
    status: stringType("process"),
    size: PropTypes.string.def(""),
    progressDot: PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func]).def(void 0),
    initial: PropTypes.number.def(0),
    current: PropTypes.number.def(0),
    items: PropTypes.array.def(() => []),
    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, {
        ...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", {
        "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 { VcSteps as default };
//# sourceMappingURL=Steps.mjs.map
