import { useCallback } from "react";
import cs from "../_util/classNames.js";
import { isFunction, isObject } from "../_util/is.js";
import IconExclamationCircleFill from "../../icon/react-icon/IconExclamationCircleFill/index.js";
import { jsxs, jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var getBackground = function(color, percent) {
  if (isObject(color)) {
    var val = Object.keys(color).map(function(key) {
      return color[key] + " " + key;
    }).join(",");
    var sizeProps = percent ? {
      backgroundSize: 100 * 100 / percent + "%"
    } : {};
    return __assign({
      backgroundImage: "linear-gradient(to right, " + val + ")"
    }, sizeProps);
  }
  return {
    backgroundColor: color
  };
};
var defaultStrokeWidth = {
  small: 3,
  default: 4,
  large: 8
};
function LineProgress(props) {
  var _a, _b;
  var type = props.type, size = props.size, prefixCls = props.prefixCls, buffer = props.buffer, percent = props.percent, status = props.status, color = props.color, animation = props.animation, showText = props.showText, bufferColor = props.bufferColor, formatText = props.formatText, trailColor = props.trailColor;
  var strokeWidth = props.strokeWidth || defaultStrokeWidth[size];
  var cls = prefixCls + "-" + type;
  var height = strokeWidth;
  var isFinish = status === "success" || status === "error" || percent >= 100;
  var getText = useCallback(function() {
    if (isFunction(formatText)) {
      return formatText(percent);
    }
    switch (status) {
      case "error":
        return /* @__PURE__ */ jsxs("span", {
          children: [percent, "% ", /* @__PURE__ */ jsx(IconExclamationCircleFill, {})]
        });
      default:
        return percent + "%";
    }
  }, [formatText, percent, status]);
  return /* @__PURE__ */ jsxs("div", {
    className: cls + "-wrapper",
    children: [/* @__PURE__ */ jsxs("div", {
      className: cls + "-outer",
      role: "progressbar",
      "aria-valuemin": 0,
      "aria-valuemax": 100,
      "aria-valuenow": percent,
      style: {
        height,
        backgroundColor: trailColor
      },
      children: [buffer && !isFinish && /* @__PURE__ */ jsx("div", {
        className: cls + "-inner-buffer",
        style: __assign({
          width: (percent > 0 ? percent + 10 : 0) + "%"
        }, getBackground(bufferColor))
      }), /* @__PURE__ */ jsx("div", {
        className: cs(cls + "-inner", (_a = {}, _a[cls + "-inner-animate"] = animation, _a)),
        style: __assign({
          width: percent + "%"
        }, getBackground(color, percent))
      })]
    }), showText && /* @__PURE__ */ jsx("div", {
      className: cs(cls + "-text", (_b = {}, _b[cls + "-text-with-icon"] = status, _b)),
      children: getText()
    })]
  });
}
LineProgress.defaultProps = {
  showText: true,
  size: "default",
  status: "normal"
};
export {
  LineProgress as default
};
//# sourceMappingURL=line-progess.js.map
