'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
var devWarning = require('../vc-util/devWarning.js');
require('../hooks/index.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var Line = require('./Line.js');
var Steps = require('./Steps.js');
var utils = require('./utils.js');
var props = require('./props.js');
var Circle = require('./Circle.js');
var index = require('./style/index.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
var Progress = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AProgress",
  inheritAttrs: false,
  props: initDefaultProps.default(props.progressProps(), {
    type: "line",
    percent: 0,
    showInfo: true,
    // null for different theme definition
    trailColor: null,
    size: "default",
    strokeLinecap: "round"
  }),
  slots: Object,
  setup(props$1, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject.default("progress", props$1);
    const [wrapSSR, hashId] = index.default(prefixCls);
    if (process.env.NODE_ENV !== "production") {
      devWarning.default("successPercent" in props$1, "Progress", "`successPercent` is deprecated. Please use `success.percent` instead.");
      devWarning.default("width" in props$1, "Progress", "`width` is deprecated. Please use `size` instead.");
    }
    const strokeColorNotArray = vue.computed(() => Array.isArray(props$1.strokeColor) ? props$1.strokeColor[0] : props$1.strokeColor);
    const percentNumber = vue.computed(() => {
      const {
        percent = 0
      } = props$1;
      const successPercent = utils.getSuccessPercent(props$1);
      return parseInt(successPercent !== void 0 ? successPercent.toString() : percent.toString(), 10);
    });
    const progressStatus = vue.computed(() => {
      const {
        status
      } = props$1;
      if (!props.progressStatuses.includes(status) && percentNumber.value >= 100)
        return "success";
      return status || "normal";
    });
    const classString = vue.computed(() => {
      const {
        type,
        showInfo,
        size
      } = props$1;
      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$1.strokeColor === "string" || Array.isArray(props$1.strokeColor) ? props$1.strokeColor : void 0);
    const renderProcessInfo = () => {
      const {
        showInfo,
        format,
        type,
        percent,
        title
      } = props$1;
      const successPercent = utils.getSuccessPercent(props$1);
      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(CloseOutlined.CloseCircleFilled, null, null) : vue.createVNode(CloseOutlined.CloseOutlined, null, null);
      else if (progressStatus.value === "success")
        text = isLineType ? vue.createVNode(CloseOutlined.CheckCircleFilled, null, null) : vue.createVNode(CloseOutlined.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$1;
      const {
        class: cls,
        ...restAttrs
      } = attrs;
      const progressInfo = renderProcessInfo();
      let progress;
      if (type === "line") {
        progress = steps ? vue.createVNode(Steps.default, vue.mergeProps(props$1, {
          "strokeColor": strokeColorNotGradient.value,
          "prefixCls": prefixCls.value,
          "steps": steps
        }), _isSlot(progressInfo) ? progressInfo : {
          default: () => [progressInfo]
        }) : vue.createVNode(Line.default, vue.mergeProps(props$1, {
          "strokeColor": strokeColorNotArray.value,
          "prefixCls": prefixCls.value,
          "direction": direction.value
        }), _isSlot(progressInfo) ? progressInfo : {
          default: () => [progressInfo]
        });
      } else if (type === "circle" || type === "dashboard") {
        progress = vue.createVNode(Circle.default, vue.mergeProps(props$1, {
          "prefixCls": prefixCls.value,
          "strokeColor": strokeColorNotArray.value,
          "progressStatus": progressStatus.value
        }), _isSlot(progressInfo) ? progressInfo : {
          default: () => [progressInfo]
        });
      }
      return wrapSSR(vue.createVNode("div", vue.mergeProps({
        "role": "progressbar"
      }, restAttrs, {
        "class": [classString.value, cls],
        "title": title
      }), [progress]));
    };
  }
});

exports.default = Progress;
//# sourceMappingURL=progress.js.map
