'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../constants/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var Line = require('./Line.cjs');
var Steps = require('./Steps.cjs');
var utils = require('./utils.cjs');
var Circle = require('./Circle.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var log = require('../../../utils/log.cjs');
var status = require('../../../constants/status.cjs');

var AProgress = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AProgress",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.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.default("progress", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    if (process.env.NODE_ENV !== "production") {
      log.devWarning("successPercent" in props, "Progress", "`successPercent` is deprecated. Please use `success.percent` instead.");
      log.devWarning("width" in props, "Progress", "`width` is deprecated. Please use `size` instead.");
    }
    const strokeColorNotArray = vue.computed(() => Array.isArray(props.strokeColor) ? props.strokeColor[0] : props.strokeColor);
    const percentNumber = vue.computed(() => {
      const {
        percent = 0
      } = props;
      const successPercent = utils.getSuccessPercent(props);
      return Number.parseInt(successPercent !== void 0 ? successPercent.toString() : percent.toString(), 10);
    });
    const progressStatus = vue.computed(() => {
      const {
        status: status$1
      } = props;
      if (!status.progressStatuses.includes(status$1) && percentNumber.value >= 100)
        return "success";
      return status$1 || "normal";
    });
    const classString = vue.computed(() => {
      const {
        type,
        showInfo,
        size
      } = props;
      const pre = prefixCls.value;
      return {
        [pre]: true,
        [`${pre}-inline-circle`]: type === "circle" && utils.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 = vue.computed(() => typeof props.strokeColor === "string" || Array.isArray(props.strokeColor) ? props.strokeColor : void 0);
    const renderProcessInfo = () => {
      const {
        showInfo,
        format,
        type,
        percent,
        title
      } = props;
      const successPercent = utils.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(utils.validProgress(percent), utils.validProgress(successPercent));
      else if (progressStatus.value === "exception")
        text = isLineType ? vue.createVNode(iconsVue.CloseCircleFilled, null, null) : vue.createVNode(iconsVue.CloseOutlined, null, null);
      else if (progressStatus.value === "success")
        text = isLineType ? vue.createVNode(iconsVue.CheckCircleFilled, null, null) : vue.createVNode(iconsVue.CheckOutlined, null, null);
      return vue.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 ? vue.createVNode(Steps.default, {
          ...props,
          "strokeColor": strokeColorNotGradient.value,
          "prefixCls": prefixCls.value,
          "steps": steps
        }, {
          default: () => [progressInfo]
        }) : vue.createVNode(Line.default, {
          ...props,
          "strokeColor": strokeColorNotArray.value,
          "prefixCls": prefixCls.value,
          "direction": direction.value
        }, {
          default: () => [progressInfo]
        });
      } else if (type === "circle" || type === "dashboard") {
        progress = vue.createVNode(Circle.default, {
          ...props,
          "prefixCls": prefixCls.value,
          "strokeColor": strokeColorNotArray.value,
          "progressStatus": progressStatus.value
        }, {
          default: () => [progressInfo]
        });
      }
      return wrapSSR(vue.createVNode("div", {
        "role": "progressbar",
        ...restAttrs,
        "class": [classString.value, cls],
        "title": title
      }, [progress]));
    };
  }
});

exports.default = AProgress;
//# sourceMappingURL=Progress.cjs.map
