"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var R = 15.915494309189533;
var C = 20;
var CIRCLE_PROPS = {
  cx: C,
  cy: C,
  r: R,
  fill: 'transparent',
  strokeWidth: 8
};
var SIZES = {
  s: 64,
  l: 215
};
var StyledSvg = _styledComponents.default.svg.withConfig({
  displayName: "ProgressDonutChart__StyledSvg",
  componentId: "sc-5hm7pl-0"
})(["transform:rotate(-90deg);circle:first-of-type{stroke:", ";}circle:nth-of-type(2){stroke:", ";animation:progress 0.5s ease-out forwards;}@keyframes progress{0%{stroke-dasharray:", ";}}"], function (t) {
  return t.theme.colorTokens.neutral.background_medium;
}, function (t) {
  return t.theme.colorTokens.action.background_default;
}, function (p) {
  return (p === null || p === void 0 ? void 0 : p.$initialStrokeDasharray) || '0 100';
});
var ProgressDonutChart = function ProgressDonutChart(_ref) {
  var completed = _ref.completed,
    _ref$total = _ref.total,
    total = _ref$total === void 0 ? 100 : _ref$total,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 's' : _ref$size;
  var sizePx = SIZES[size];
  var strokeDasharray = "".concat(100 * completed / total, " ").concat(100 * (1 - completed / total));
  var savedStrokeDasharray = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    savedStrokeDasharray.current = strokeDasharray;
  }, [strokeDasharray]);
  return _react.default.createElement(StyledSvg, {
    width: sizePx,
    height: sizePx,
    viewBox: "0 0 ".concat(2 * C, " ").concat(2 * C),
    key: "".concat(size, ":").concat(completed),
    $initialStrokeDasharray: savedStrokeDasharray.current && savedStrokeDasharray.current !== strokeDasharray ? savedStrokeDasharray.current : undefined
  }, _react.default.createElement("circle", CIRCLE_PROPS), completed > 0 && total > 0 && _react.default.createElement("circle", _extends({}, CIRCLE_PROPS, {
    strokeDasharray: strokeDasharray
  })));
};
var _default = exports.default = ProgressDonutChart;