import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import * as React from 'react';
import { VIEWBOX_WIDTH, VIEWBOX_HEIGHT, VIEWBOX_HEIGHT_HALF, VIEWBOX_CENTER_X, VIEWBOX_CENTER_Y } from './constants';
import Path from './Path';
var CircularProgressbar = /*#__PURE__*/function (_React$Component) {
  function CircularProgressbar() {
    _classCallCheck(this, CircularProgressbar);
    return _callSuper(this, CircularProgressbar, arguments);
  }
  _inherits(CircularProgressbar, _React$Component);
  return _createClass(CircularProgressbar, [{
    key: "getBackgroundPadding",
    value: function getBackgroundPadding() {
      if (!this.props.background) {
        // Don't add padding if not displaying background
        return 0;
      }
      return this.props.backgroundPadding;
    }
  }, {
    key: "getPathRadius",
    value: function getPathRadius() {
      // The radius of the path is defined to be in the middle, so in order for the path to
      // fit perfectly inside the 100x100 viewBox, need to subtract half the strokeWidth
      return VIEWBOX_HEIGHT_HALF - this.props.strokeWidth / 2 - this.getBackgroundPadding();
    }

    // Ratio of path length to trail length, as a value between 0 and 1
  }, {
    key: "getPathRatio",
    value: function getPathRatio() {
      var _this$props = this.props,
        value = _this$props.value,
        minValue = _this$props.minValue,
        maxValue = _this$props.maxValue;
      var boundedValue = Math.min(Math.max(value, minValue), maxValue);
      return (boundedValue - minValue) / (maxValue - minValue);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
        circleRatio = _this$props2.circleRatio,
        className = _this$props2.className,
        classes = _this$props2.classes,
        counterClockwise = _this$props2.counterClockwise,
        styles = _this$props2.styles,
        strokeWidth = _this$props2.strokeWidth,
        text = _this$props2.text;
      var pathRadius = this.getPathRadius();
      var pathRatio = this.getPathRatio();
      return /*#__PURE__*/React.createElement("svg", {
        className: "".concat(classes.root, " ").concat(className),
        style: styles.root,
        viewBox: "0 0 ".concat(VIEWBOX_WIDTH, " ").concat(VIEWBOX_HEIGHT),
        "data-test-id": "CircularProgressbar"
      }, this.props.background ? /*#__PURE__*/React.createElement("circle", {
        className: classes.background,
        style: styles.background,
        cx: VIEWBOX_CENTER_X,
        cy: VIEWBOX_CENTER_Y,
        r: VIEWBOX_HEIGHT_HALF
      }) : null, /*#__PURE__*/React.createElement(Path, {
        className: classes.trail,
        counterClockwise: counterClockwise,
        dashRatio: circleRatio,
        pathRadius: pathRadius,
        strokeWidth: strokeWidth,
        style: styles.trail
      }), /*#__PURE__*/React.createElement(Path, {
        className: classes.path,
        counterClockwise: counterClockwise,
        dashRatio: pathRatio * circleRatio,
        pathRadius: pathRadius,
        strokeWidth: strokeWidth,
        style: styles.path
      }), text ? /*#__PURE__*/React.createElement("text", {
        className: classes.text,
        style: styles.text,
        x: VIEWBOX_CENTER_X,
        y: VIEWBOX_CENTER_Y
      }, text) : null);
    }
  }]);
}(React.Component);
_defineProperty(CircularProgressbar, "defaultProps", {
  background: false,
  backgroundPadding: 0,
  circleRatio: 1,
  classes: {
    root: 'CircularProgressbar',
    trail: 'CircularProgressbar-trail',
    path: 'CircularProgressbar-path',
    text: 'CircularProgressbar-text',
    background: 'CircularProgressbar-background'
  },
  counterClockwise: false,
  className: '',
  maxValue: 100,
  minValue: 0,
  strokeWidth: 8,
  styles: {
    root: {},
    trail: {},
    path: {},
    text: {},
    background: {}
  },
  text: ''
});
export default CircularProgressbar;