"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.circularProgressStyle = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _ThemeProvider = require("../ThemeProvider");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var circularProgressStyle = function circularProgressStyle(_ref, theme) {
  var _ref$size = _ref.size,
      size = _ref$size === void 0 ? 48 : _ref$size,
      _ref$min = _ref.min,
      min = _ref$min === void 0 ? 0 : _ref$min,
      _ref$max = _ref.max,
      max = _ref$max === void 0 ? 100 : _ref$max,
      _ref$color = _ref.color,
      color = _ref$color === void 0 ? 'progress' : _ref$color,
      _ref$trackColor = _ref.trackColor,
      trackColor = _ref$trackColor === void 0 ? 'track' : _ref$trackColor,
      isIndeterminate = _ref.isIndeterminate,
      value = _ref.value,
      _ref$thickness = _ref.thickness,
      thickness = _ref$thickness === void 0 ? 0.2 : _ref$thickness,
      _ref$angle = _ref.angle,
      angle = _ref$angle === void 0 ? 0 : _ref$angle,
      capIsRound = _ref.capIsRound,
      spin = _ref.spin,
      circularProgressCircle = _ref.circularProgressCircle;
  var radius = 50;
  var diameter = radius * 2;
  var circumference = diameter * Math.PI;
  var strokeDasharray = Math.round(circumference * 1000) / 1000;
  var viewBox = diameter / (1 - thickness / 2);
  var viewBoxAttr = "".concat(viewBox / 2, " ").concat(viewBox / 2, " ").concat(viewBox, " ").concat(viewBox);
  var strokeWidth = thickness / 2 * viewBox;
  var progress = 1 - (value - min) / (max - min);
  var strokeDashoffset = progress * circumference;

  function getCircleProps(_ref2) {
    var circleThickness = _ref2.thickness,
        offset = _ref2.offset,
        circleColor = _ref2.color;
    return {
      as: 'circle',
      color: circleColor,
      fill: 'transparent',
      stroke: 'currentColor',
      strokeWidth: circleThickness,
      strokeDasharray: strokeDasharray,
      strokeDashoffset: offset,
      cx: viewBox,
      cy: viewBox,
      r: radius
    };
  }

  return {
    style: {
      size: '1em',
      fontSize: size,
      display: 'inline-block',
      position: 'relative',
      veriticalAlign: 'middle',
      role: 'progressbar',
      'aria-valuemin': min,
      'aria-valuemax': max,
      'aria-valuenow': isIndeterminate ? null : value
    },
    svg: _objectSpread({
      as: 'svg',
      viewBox: viewBoxAttr,
      verticalAlign: 'top',
      transform: "rotate3d(0, 0, 1, ".concat(angle - 90, "deg)"),
      size: '100%'
    }, isIndeterminate && {
      transformOrigin: '50% 50%',
      animation: "".concat(spin, " 2s linear infinite")
    }),
    track: getCircleProps({
      thickness: strokeWidth,
      offset: 0,
      color: trackColor
    }),
    indicator: _objectSpread(_objectSpread(_objectSpread({
      stroke: 'currentColor'
    }, getCircleProps({
      thickness: strokeWidth,
      offset: strokeDashoffset,
      color: color
    })), capIsRound && {
      strokeLinecap: 'round'
    }), isIndeterminate && {
      transition: 'stroke-dashoffset 0.6s ease 0s, stroke 0.6s ease',
      animation: "".concat(circularProgressCircle, " 1.5s ease-in-out infinite"),
      strokeDasharray: '1 400',
      strokeDashoffset: '0'
    })
  };
};

exports.circularProgressStyle = circularProgressStyle;

var useCircularProgressStyle = function useCircularProgressStyle(props) {
  var theme = (0, _ThemeProvider.useTheme)();
  var styles = theme['styles'].circularProgress ? theme['styles'].circularProgress(props, theme) : circularProgressStyle(props, theme);
  return {
    // base style
    root: styles.style,
    svg: styles.svg,
    track: styles.track,
    indicator: styles.indicator
  };
};

var _default = useCircularProgressStyle;
exports["default"] = _default;
//# sourceMappingURL=styles.js.map