import { useCallback } from "react";
import { isObject, isFunction } from "../_util/is.js";
import IconCheck from "../../icon/react-icon/IconCheck/index.js";
import IconExclamation from "../../icon/react-icon/IconExclamation/index.js";
import Tooltip from "../Tooltip/index.js";
import useId from "../_util/hooks/useId.js";
import { jsx, jsxs } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var defaultStrokeWidth = {
  mini: 4,
  small: 3,
  default: 4,
  large: 4
};
var defaultWidth = {
  mini: 16,
  small: 48,
  default: 64,
  large: 80
};
var CircleProgress = function(props) {
  var size = props.size, _a = props.percent, percent = _a === void 0 ? 0 : _a, prefixCls = props.prefixCls, showText = props.showText, status = props.status, formatText = props.formatText;
  var isLinearGradient = isObject(props.color);
  var width = props.width || defaultWidth[size];
  var strokeWidth = props.strokeWidth || (size === "mini" ? width / 2 : defaultStrokeWidth[size]);
  var radius = (width - strokeWidth) / 2;
  var perimeter = Math.PI * 2 * radius;
  var center = width / 2;
  var cls = prefixCls + "-circle";
  var svgCls = cls + "-svg";
  var getText = useCallback(function(status2) {
    if (isFunction(formatText)) {
      return formatText(percent);
    }
    switch (status2) {
      case "success":
        return /* @__PURE__ */ jsx(IconCheck, {});
      case "error":
        return /* @__PURE__ */ jsx(IconExclamation, {});
      default:
        return percent + "%";
    }
  }, [formatText, percent]);
  var linearGradientId = useId(prefixCls + "-linear-gradient-");
  var color = isLinearGradient ? "url(#" + linearGradientId + ")" : props.color;
  var dom = /* @__PURE__ */ jsxs("div", {
    className: cls + "-wrapper",
    role: "progressbar",
    "aria-valuemin": 0,
    "aria-valuemax": 100,
    "aria-valuenow": percent,
    style: {
      width,
      height: width
    },
    children: [/* @__PURE__ */ jsxs("svg", {
      viewBox: "0 0 " + width + " " + width,
      className: "" + svgCls,
      children: [isLinearGradient && /* @__PURE__ */ jsx("defs", {
        children: /* @__PURE__ */ jsx("linearGradient", {
          id: linearGradientId,
          x1: "0",
          y1: "1",
          x2: "0",
          y2: "0",
          children: Object.keys(props.color).sort().map(function(key) {
            return /* @__PURE__ */ jsx("stop", {
              offset: key,
              stopColor: props.color[key]
            }, key);
          })
        })
      }), /* @__PURE__ */ jsx("circle", {
        className: cls + "-mask",
        fill: "none",
        cx: center,
        cy: center,
        r: radius,
        strokeWidth: props.pathStrokeWidth || (size === "mini" ? strokeWidth : Math.max(2, strokeWidth - 2)),
        style: {
          stroke: props.pathStrokeColor
        }
      }), /* @__PURE__ */ jsx("circle", {
        className: cls + "-path",
        fill: "none",
        cx: center,
        cy: center,
        r: radius,
        strokeWidth,
        style: {
          stroke: color,
          strokeDasharray: perimeter,
          strokeDashoffset: (percent > 100 ? 100 : 1 - percent / 100) * perimeter
        }
      })]
    }), showText && size !== "mini" && /* @__PURE__ */ jsx("div", {
      className: cls + "-text",
      children: getText(status)
    })]
  });
  if (size === "mini" && status === "success" && props.type === "circle") {
    dom = /* @__PURE__ */ jsx("div", {
      className: cls + "-wrapper",
      style: {
        width,
        height: width
      },
      children: /* @__PURE__ */ jsx(IconCheck, {
        style: {
          fontSize: width - 2,
          color
        }
      })
    });
  }
  return size === "mini" && showText ? /* @__PURE__ */ jsx(Tooltip, {
    content: /* @__PURE__ */ jsx("div", {
      className: cls + "-text",
      children: getText("normal")
    }),
    children: dom
  }) : dom;
};
const CircleProgress$1 = CircleProgress;
export {
  CircleProgress$1 as default
};
//# sourceMappingURL=circle-progress.js.map
