"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ProgressRing = exports.ProgressCircle = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Styles = require("./Styles");
var _excluded = ["className", "children"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var ProgressCircle = exports.ProgressCircle = function ProgressCircle(_ref) {
  var backgroundColor = _ref.backgroundColor,
    progressColor = _ref.progressColor,
    _ref$progress = _ref.progress,
    progress = _ref$progress === void 0 ? 0 : _ref$progress,
    _ref$radius = _ref.radius,
    radius = _ref$radius === void 0 ? 20 : _ref$radius,
    _ref$stroke = _ref.stroke,
    stroke = _ref$stroke === void 0 ? 3 : _ref$stroke,
    _ref$roundStroke = _ref.roundStroke,
    roundStroke = _ref$roundStroke === void 0 ? false : _ref$roundStroke,
    className = _ref.className,
    _ref$showPercentage = _ref.showPercentage,
    showPercentage = _ref$showPercentage === void 0 ? false : _ref$showPercentage,
    fontSize = _ref.fontSize;
  if (stroke > radius) {
    console.warn("Stroke can not have value greater than the radius.");
    stroke = radius;
  }
  var progressNumber = (0, _react.useMemo)(function () {
    var width = progress;
    if (progress > 100) {
      width = 100;
    }
    if (progress < 0) {
      width = 0;
    }
    return width;
  }, [progress]);
  var normalizedRadius = (0, _react.useMemo)(function () {
    return radius - stroke / 2;
  }, [radius, stroke]);
  var circumference = (0, _react.useMemo)(function () {
    return normalizedRadius * 2 * Math.PI;
  }, [normalizedRadius]);
  var strokeDashoffsetOuter = (0, _react.useMemo)(function () {
    return circumference - (100 - progressNumber) / 100 * circumference;
  }, [circumference, progressNumber]);
  var strokeDashoffsetInner = (0, _react.useMemo)(function () {
    return circumference - progressNumber / 100 * circumference;
  }, [circumference, progressNumber]);
  return /*#__PURE__*/_react.default.createElement(_Styles.StyledSvg, {
    height: radius * 2,
    width: radius * 2,
    className: className,
    "data-progress": progressNumber,
    "data-testid": "progress-circle"
  }, /*#__PURE__*/_react.default.createElement(_Styles.StyledBackgroundCircle, {
    $color: backgroundColor,
    $strokeDashOffset: -strokeDashoffsetOuter,
    strokeWidth: stroke,
    strokeDasharray: "".concat(circumference, " ").concat(circumference),
    r: normalizedRadius,
    cx: radius,
    cy: radius
  }), /*#__PURE__*/_react.default.createElement(_Styles.StyledForegroundCircle, {
    $color: progressColor,
    $strokeDashOffset: strokeDashoffsetInner,
    strokeWidth: stroke,
    strokeDasharray: "".concat(circumference, " ").concat(circumference),
    $roundStroke: roundStroke,
    r: normalizedRadius,
    cx: radius,
    cy: radius
  }), showPercentage ? /*#__PURE__*/_react.default.createElement(_Styles.StyledProgressRingPercentage, {
    $color: progressColor,
    $fontSize: fontSize,
    x: "50%",
    y: "-50%",
    dominantBaseline: "central",
    textAnchor: "middle"
  }, progressNumber, "%") : null);
};
var ProgressRing = exports.ProgressRing = function ProgressRing(_ref2) {
  var className = _ref2.className,
    children = _ref2.children,
    rest = _objectWithoutProperties(_ref2, _excluded);
  return /*#__PURE__*/_react.default.createElement(_Styles.StyledWrapper, {
    className: (0, _classnames.default)(className),
    "data-testid": "progress-ring"
  }, /*#__PURE__*/_react.default.createElement(ProgressCircle, rest), children ? /*#__PURE__*/_react.default.createElement(_Styles.StyledChildrenWrapper, null, children) : null);
};
ProgressRing.displayName = "ProgressRing";
//# sourceMappingURL=ProgressRing.js.map