"use strict";

exports.__esModule = true;
exports.default = void 0;
var _isNull2 = _interopRequireDefault(require("lodash/fp/isNull"));
var _react = _interopRequireWildcard(require("react"));
var _types = require("./types");
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (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 && {}.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 _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ProgressionGradient = () => /*#__PURE__*/_react.default.createElement("defs", null, /*#__PURE__*/_react.default.createElement("linearGradient", {
  id: "gradient-stroke-progression",
  x1: "81",
  y1: "0",
  x2: "81",
  y2: "162",
  gradientUnits: "userSpaceOnUse"
}, /*#__PURE__*/_react.default.createElement("stop", {
  stopColor: "#35CC7F"
}), /*#__PURE__*/_react.default.createElement("stop", {
  offset: "1",
  stopColor: "#55F2A7"
})));
const CircularProgressBar = ({
  label,
  progression,
  size,
  strokeWidth,
  'aria-label': ariaLabel,
  'data-name': dataName
}) => {
  const [offset, setOffset] = (0, _react.useState)(null);
  const {
    center,
    radius,
    length
  } = (0, _react.useMemo)(() => {
    const center_ = size / 2;
    const radius_ = center_ - strokeWidth;
    const length_ = Math.ceil(2 * Math.PI * radius_);
    return {
      center: center_,
      radius: radius_,
      length: length_
    };
  }, [size, strokeWidth]);
  (0, _react.useEffect)(() => setOffset(Math.ceil(length * ((100 - progression) / 100))), [length, progression]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.container,
    "aria-label": ariaLabel,
    "data-name": dataName
  }, /*#__PURE__*/_react.default.createElement("svg", {
    className: _style.default.svg,
    width: size,
    height: size
  }, /*#__PURE__*/_react.default.createElement(ProgressionGradient, null), /*#__PURE__*/_react.default.createElement("circle", {
    className: _style.default.mainCircle,
    cx: center,
    cy: center,
    r: radius,
    strokeWidth: 3,
    fill: "transparent"
  }), /*#__PURE__*/_react.default.createElement("circle", {
    cx: center,
    cy: center,
    r: radius - 10 / radius * 100,
    fill: "#fafafa"
  }), /*#__PURE__*/_react.default.createElement("circle", {
    className: _style.default.progressionCircle,
    cx: center,
    cy: center,
    r: radius,
    stroke: `url(#gradient-stroke-progression)`,
    strokeWidth: strokeWidth,
    strokeDasharray: length,
    strokeDashoffset: (0, _isNull2.default)(offset) ? length : offset,
    fill: "transparent",
    strokeLinecap: "round"
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.infos
  }, /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.progression
  }, progression, "%"), /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.label
  }, label)));
};
CircularProgressBar.propTypes = process.env.NODE_ENV !== "production" ? _types.CircularProgressBarPropTypes : {};
var _default = exports.default = CircularProgressBar;
//# sourceMappingURL=index.js.map