import React, { useContext, useMemo } from "react";
import classnames from "classnames";
import { addUnit } from "../utils";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const Progress = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("progress", prefixCls);
  const {
    inactive,
    color,
    trackColor,
    percentage,
    strokeWidth
  } = props;
  const background = useMemo(() => {
    return inactive ? void 0 : color;
  }, [inactive, color]);
  const renderPivot = () => {
    const {
      textColor,
      pivotText,
      pivotColor
    } = props;
    const text = pivotText != null ? pivotText : `${percentage}%`;
    if (props.showPivot && text) {
      const style = {
        color: textColor,
        left: `${+percentage}%`,
        transform: `translate(-${+percentage}%,-50%)`,
        background: pivotColor || background
      };
      return /* @__PURE__ */ React.createElement("span", {
        style,
        className: bem("pivot", {
          inactive: props.inactive
        })
      }, text);
    }
    return null;
  };
  const rootStyle = {
    background: trackColor,
    height: addUnit(strokeWidth)
  };
  const portionStyle = {
    width: `${percentage}%`,
    background
  };
  return /* @__PURE__ */ React.createElement("div", {
    className: classnames(props.className, bem()),
    style: rootStyle
  }, /* @__PURE__ */ React.createElement("span", {
    className: classnames(bem("portion", {
      inactive: props.inactive
    })),
    style: portionStyle
  }), renderPivot());
};
Progress.defaultProps = {
  percentage: 0,
  strokeWidth: "4px",
  color: "#1989fa",
  trackColor: "#e5e5e5",
  pivotColor: "",
  textColor: "white",
  inactive: false,
  showPivot: true
};
var stdin_default = Progress;
export {
  stdin_default as default
};
