"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _box = _interopRequireDefault(require("../../box/box"));
var _indicator = _interopRequireDefault(require("./indicator"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
/** A component used to provide a visual cue that an action is either processing, awaiting a course of change or a result. */
const BarIndicator = /*#__PURE__*/_react.default.memo( /*#__PURE__*/_react.default.forwardRef(({
  count = 3,
  size = 30,
  color = "rgb(0, 0, 0)",
  ...rest
}, ref) => {
  const outputRange = _react.default.useCallback((base, index, count, samples) => {
    let range = Array.from(new Array(samples), (item, index) => base * Math.abs(Math.cos(Math.PI * index / (samples - 1))));
    for (let j = 0; j < index * (samples / count); j++) {
      range.unshift(range.pop());
    }
    range.unshift(...range.slice(-1));
    return range;
  }, []);
  const _renderComponent = _react.default.useCallback(({
    index,
    count,
    progress
  }) => {
    let frames = 60 * rest.animationDuration / 1000;
    let samples = 0;
    do samples += count; while (samples < frames);
    let inputRange = Array.from(new Array(samples + 1), (item, index) => index / samples);
    let width = Math.floor(size / 5),
      height = Math.floor(size / 2),
      radius = Math.ceil(width / 2);
    let containerStyle = {
      height: size,
      width: width,
      marginHorizontal: radius
    };
    let topStyle = {
      width,
      height,
      backgroundColor: color,
      borderTopLeftRadius: radius,
      borderTopRightRadius: radius,
      transform: [{
        translateY: progress.interpolate({
          inputRange,
          outputRange: outputRange(+(height - radius) / 2, index, count, samples)
        })
      }]
    };
    let bottomStyle = {
      width,
      height,
      backgroundColor: color,
      borderBottomLeftRadius: radius,
      borderBottomRightRadius: radius,
      transform: [{
        translateY: progress.interpolate({
          inputRange,
          outputRange: outputRange(-(height - radius) / 2, index, count, samples)
        })
      }]
    };
    return /*#__PURE__*/_react.default.createElement(_box.default, {
      style: containerStyle,
      key: index
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
      style: topStyle
    }), /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
      style: bottomStyle
    }));
  }, [outputRange]);
  return /*#__PURE__*/_react.default.createElement(_indicator.default, _extends({}, rest, {
    ref: ref,
    style: [{
      flexDirection: "row",
      justifyContent: "center",
      alignItems: "center"
    }, rest.style],
    renderComponent: _renderComponent,
    count: count
  }));
}));
var _default = exports.default = BarIndicator;
//# sourceMappingURL=bar.js.map