'use strict';

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

var vue = require('vue');
var index = require('../_util/vue-types/index.js');
var classNames = require('../_util/classNames.js');
var type = require('../_util/type.js');
var index$1 = require('../_util/props-util/index.js');
var vnode = require('../_util/vnode.js');
var Step = require('./Step.js');

var Steps = /* @__PURE__ */ vue.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: type.stringType("process"),
    size: {
      type: String,
      default: ""
    },
    progressDot: index.default.oneOfType([index.default.looseBool, index.default.func]).def(void 0),
    initial: {
      type: Number,
      default: 0
    },
    current: {
      type: Number,
      default: 0
    },
    items: {
      type: Array,
      default: () => []
    },
    icons: index.default.shape({
      finish: index.default.any,
      error: index.default.any
    }).loose,
    stepIcon: type.functionType(),
    isInline: index.default.looseBool,
    itemRender: type.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 vue.createVNode(Step.default, vue.mergeProps(mergedItem, commonProps, {
        "__legacy": false
      }), null);
    };
    const renderStepWithNode = (node, index) => {
      return renderStep({
        ...node.props
      }, index, (stepProps) => {
        const stepNode = vnode.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.default(prefixCls, `${prefixCls}-${direction}`, {
        [`${prefixCls}-${mergedSize}`]: mergedSize,
        [`${prefixCls}-label-${adjustedLabelPlacement}`]: mergedDirection === "horizontal",
        [`${prefixCls}-dot`]: !!mergedProgressDot,
        [`${prefixCls}-navigation`]: isNav,
        [`${prefixCls}-inline`]: isInline
      });
      return vue.createVNode("div", vue.mergeProps({
        "class": classString
      }, restProps), [items.filter((item) => item).map((item, index) => renderStep(item, index)), index$1.filterEmpty((_a = slots.default) == null ? void 0 : _a.call(slots)).map(renderStepWithNode)]);
    };
  }
});

exports.default = Steps;
//# sourceMappingURL=Steps.js.map
