import { defineComponent, computed, createVNode } from 'vue';
import { CloseCircleFilled, CloseOutlined, CheckCircleFilled, CheckOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../constants/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import useStyle from '../style/index.mjs';
import Line from './Line.mjs';
import Steps from './Steps.mjs';
import { getSuccessPercent, getSize, validProgress } from './utils.mjs';
import Circle from './Circle.mjs';
import { progressProps } from './props.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { progressStatuses } from '../../../constants/status.mjs';

var AProgress = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AProgress",
  inheritAttrs: false,
  props: initDefaultProps(progressProps(), {
    type: "line",
    percent: 0,
    showInfo: true,
    // null for different theme definition
    trailColor: null,
    size: "default",
    strokeLinecap: "round"
  }),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject("progress", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    if (process.env.NODE_ENV !== "production") {
      devWarning("successPercent" in props, "Progress", "`successPercent` is deprecated. Please use `success.percent` instead.");
      devWarning("width" in props, "Progress", "`width` is deprecated. Please use `size` instead.");
    }
    const strokeColorNotArray = computed(() => Array.isArray(props.strokeColor) ? props.strokeColor[0] : props.strokeColor);
    const percentNumber = computed(() => {
      const {
        percent = 0
      } = props;
      const successPercent = getSuccessPercent(props);
      return Number.parseInt(successPercent !== void 0 ? successPercent.toString() : percent.toString(), 10);
    });
    const progressStatus = computed(() => {
      const {
        status
      } = props;
      if (!progressStatuses.includes(status) && percentNumber.value >= 100)
        return "success";
      return status || "normal";
    });
    const classString = computed(() => {
      const {
        type,
        showInfo,
        size
      } = props;
      const pre = prefixCls.value;
      return {
        [pre]: true,
        [`${pre}-inline-circle`]: type === "circle" && getSize(size, "circle").width <= 20,
        [`${pre}-${type === "dashboard" && "circle" || type}`]: true,
        [`${pre}-status-${progressStatus.value}`]: true,
        [`${pre}-show-info`]: showInfo,
        [`${pre}-${size}`]: size,
        [`${pre}-rtl`]: direction.value === "rtl",
        [hashId.value]: true
      };
    });
    const strokeColorNotGradient = computed(() => typeof props.strokeColor === "string" || Array.isArray(props.strokeColor) ? props.strokeColor : void 0);
    const renderProcessInfo = () => {
      const {
        showInfo,
        format,
        type,
        percent,
        title
      } = props;
      const successPercent = getSuccessPercent(props);
      if (!showInfo)
        return null;
      let text;
      const textFormatter = format || (slots == null ? void 0 : slots.format) || ((val) => `${val}%`);
      const isLineType = type === "line";
      if (format || (slots == null ? void 0 : slots.format) || progressStatus.value !== "exception" && progressStatus.value !== "success")
        text = textFormatter(validProgress(percent), validProgress(successPercent));
      else if (progressStatus.value === "exception")
        text = isLineType ? createVNode(CloseCircleFilled, null, null) : createVNode(CloseOutlined, null, null);
      else if (progressStatus.value === "success")
        text = isLineType ? createVNode(CheckCircleFilled, null, null) : createVNode(CheckOutlined, null, null);
      return createVNode("span", {
        "class": `${prefixCls.value}-text`,
        "title": title === void 0 && typeof text === "string" ? text : void 0
      }, [text]);
    };
    return () => {
      const {
        type,
        steps,
        title
      } = props;
      const {
        class: cls,
        ...restAttrs
      } = attrs;
      const progressInfo = renderProcessInfo();
      let progress;
      if (type === "line") {
        progress = steps ? createVNode(Steps, {
          ...props,
          "strokeColor": strokeColorNotGradient.value,
          "prefixCls": prefixCls.value,
          "steps": steps
        }, {
          default: () => [progressInfo]
        }) : createVNode(Line, {
          ...props,
          "strokeColor": strokeColorNotArray.value,
          "prefixCls": prefixCls.value,
          "direction": direction.value
        }, {
          default: () => [progressInfo]
        });
      } else if (type === "circle" || type === "dashboard") {
        progress = createVNode(Circle, {
          ...props,
          "prefixCls": prefixCls.value,
          "strokeColor": strokeColorNotArray.value,
          "progressStatus": progressStatus.value
        }, {
          default: () => [progressInfo]
        });
      }
      return wrapSSR(createVNode("div", {
        "role": "progressbar",
        ...restAttrs,
        "class": [classString.value, cls],
        "title": title
      }, [progress]));
    };
  }
});

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