"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AnimatedProgressIndicator = void 0;

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

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

var _framerMotion = require("framer-motion");

var _react = _interopRequireDefault(require("react"));

var _reactIntersectionObserver = _interopRequireDefault(require("react-intersection-observer"));

var _Box = require("../Box");

var _utils = require("../Slider/utils");

var __jsx = _react["default"].createElement;

var AnimatedProgressIndicator = function AnimatedProgressIndicator(_ref) {
  var isIndeterminate = _ref.isIndeterminate,
      min = _ref.min,
      max = _ref.max,
      value = _ref.value,
      rest = (0, _objectWithoutProperties2["default"])(_ref, ["isIndeterminate", "min", "max", "value"]);
  var percent = (0, _utils.valueToPercent)(value, min, max);
  return __jsx(_reactIntersectionObserver["default"], null, function (_ref2) {
    var inView = _ref2.inView,
        ref = _ref2.ref,
        entry = _ref2.entry;
    return __jsx(_Box.Box, {
      ref: ref,
      h: "100%",
      w: "100%"
    }, inView && __jsx(_framerMotion.motion.div, {
      initial: {
        width: 0
      },
      animate: {
        width: '100%'
      },
      transition: {
        duration: 1,
        ease: 'easeInOut'
      },
      style: {
        height: '100%'
      }
    }, __jsx(_Box.Box, (0, _extends2["default"])({
      height: "100%",
      "aria-valuemax": max,
      "aria-valuemin": min,
      "aria-valuenow": isIndeterminate ? null : value,
      role: "progressbar",
      transition: "all 0.3s",
      width: "".concat(percent, "%")
    }, rest))));
  });
};

exports.AnimatedProgressIndicator = AnimatedProgressIndicator;
//# sourceMappingURL=AnimatedProgressIndicator.js.map