import { defineComponent, createVNode } from 'vue';
import '../../../utils/index.mjs';
import { stringType, functionType, booleanType } from '../../../utils/vue/propType.mjs';
import PropTypes from '../../../utils/vue/vueTypes.mjs';
import { withUndefined } from '../../../utils/vue/util.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import { omit } from '../../../utils/lang/omit.mjs';

function isString(str) {
  return typeof str === "string";
}
function noop() {
}
function VcStepProps() {
  return {
    prefixCls: String,
    itemWidth: String,
    active: {
      type: Boolean,
      default: void 0
    },
    disabled: {
      type: Boolean,
      default: void 0
    },
    status: stringType(),
    iconPrefix: String,
    icon: PropTypes.any,
    adjustMarginRight: String,
    stepNumber: Number,
    stepIndex: Number,
    description: PropTypes.any,
    title: PropTypes.any,
    subTitle: PropTypes.any,
    progressDot: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func])),
    tailContent: PropTypes.any,
    icons: PropTypes.shape({
      finish: PropTypes.any,
      error: PropTypes.any
    }).loose,
    onClick: functionType(),
    onStepClick: functionType(),
    stepIcon: functionType(),
    itemRender: functionType(),
    __legacy: booleanType()
  };
}
var VcStep = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Step",
  inheritAttrs: false,
  props: VcStepProps(),
  setup(props, {
    slots,
    emit,
    attrs
  }) {
    const onItemClick = (e) => {
      emit("click", e);
      emit("stepClick", props.stepIndex);
    };
    const renderIconNode = ({
      icon,
      title,
      description
    }) => {
      const {
        prefixCls,
        stepNumber,
        status,
        iconPrefix,
        icons,
        progressDot = slots.progressDot,
        stepIcon = slots.stepIcon
      } = props;
      let iconNode;
      const iconClassName = classNames(`${prefixCls}-icon`, `${iconPrefix}icon`, {
        [`${iconPrefix}icon-${icon}`]: icon && isString(icon),
        [`${iconPrefix}icon-check`]: !icon && status === "finish" && (icons && !icons.finish || !icons),
        [`${iconPrefix}icon-cross`]: !icon && status === "error" && (icons && !icons.error || !icons)
      });
      const iconDot = createVNode("span", {
        "class": `${prefixCls}-icon-dot`
      }, null);
      if (progressDot) {
        if (typeof progressDot === "function") {
          iconNode = createVNode("span", {
            "class": `${prefixCls}-icon`
          }, [progressDot({
            iconDot,
            index: stepNumber - 1,
            status,
            title,
            description,
            prefixCls
          })]);
        } else {
          iconNode = createVNode("span", {
            "class": `${prefixCls}-icon`
          }, [iconDot]);
        }
      } else if (icon && !isString(icon)) {
        iconNode = createVNode("span", {
          "class": `${prefixCls}-icon`
        }, [icon]);
      } else if (icons && icons.finish && status === "finish") {
        iconNode = createVNode("span", {
          "class": `${prefixCls}-icon`
        }, [icons.finish]);
      } else if (icons && icons.error && status === "error") {
        iconNode = createVNode("span", {
          "class": `${prefixCls}-icon`
        }, [icons.error]);
      } else if (icon || status === "finish" || status === "error") {
        iconNode = createVNode("span", {
          "class": iconClassName
        }, null);
      } else {
        iconNode = createVNode("span", {
          "class": `${prefixCls}-icon`
        }, [stepNumber]);
      }
      if (stepIcon) {
        iconNode = stepIcon({
          index: stepNumber - 1,
          status,
          title,
          description,
          node: iconNode
        });
      }
      return iconNode;
    };
    return () => {
      var _a, _b, _c, _d;
      const {
        prefixCls,
        itemWidth,
        active,
        status = "wait",
        tailContent,
        adjustMarginRight,
        disabled,
        title = (_a = slots.title) == null ? void 0 : _a.call(slots),
        description = (_b = slots.description) == null ? void 0 : _b.call(slots),
        subTitle = (_c = slots.subTitle) == null ? void 0 : _c.call(slots),
        icon = (_d = slots.icon) == null ? void 0 : _d.call(slots),
        onClick,
        onStepClick
      } = props;
      const mergedStatus = status || "wait";
      const classString = classNames(`${prefixCls}-item`, `${prefixCls}-item-${mergedStatus}`, {
        [`${prefixCls}-item-custom`]: icon,
        [`${prefixCls}-item-active`]: active,
        [`${prefixCls}-item-disabled`]: disabled === true
      });
      const stepItemStyle = {};
      if (itemWidth)
        stepItemStyle.width = itemWidth;
      if (adjustMarginRight)
        stepItemStyle.marginRight = adjustMarginRight;
      const accessibilityProps = {
        onClick: onClick || noop
      };
      if (onStepClick && !disabled) {
        accessibilityProps.role = "button";
        accessibilityProps.tabindex = 0;
        accessibilityProps.onClick = onItemClick;
      }
      const stepNode = createVNode("div", {
        ...omit(attrs, ["__legacy"]),
        "class": [classString, attrs.class],
        "style": [attrs.style, stepItemStyle]
      }, [createVNode("div", {
        ...accessibilityProps,
        "class": `${prefixCls}-item-container`
      }, [createVNode("div", {
        "class": `${prefixCls}-item-tail`
      }, [tailContent]), createVNode("div", {
        "class": `${prefixCls}-item-icon`
      }, [renderIconNode({
        icon,
        title,
        description
      })]), createVNode("div", {
        "class": `${prefixCls}-item-content`
      }, [createVNode("div", {
        "class": `${prefixCls}-item-title`
      }, [title, subTitle && createVNode("div", {
        "title": typeof subTitle === "string" ? subTitle : void 0,
        "class": `${prefixCls}-item-subtitle`
      }, [subTitle])]), description && createVNode("div", {
        "class": `${prefixCls}-item-description`
      }, [description])])])]);
      if (props.itemRender)
        return props.itemRender(stepNode);
      return stepNode;
    };
  }
});

export { VcStepProps, VcStep as default };
//# sourceMappingURL=Step.mjs.map
