"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
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 PacmanIndicator = /*#__PURE__*/_react.default.memo( /*#__PURE__*/_react.default.forwardRef(({
  size = 30,
  color = "rgb(0, 0, 0)",
  ...rest
}, ref) => {
  const _renderBlock = _react.default.useCallback(({
    index,
    count,
    progress
  }) => {
    let transform = [{
      translateX: progress.interpolate({
        inputRange: [0.5, 1],
        outputRange: [0, size / (_reactNative.I18nManager.isRTL ? 4 : -4)],
        extrapolate: "clamp"
      })
    }];
    let style = {
      position: "absolute",
      top: size / 2 - size / 16,
      left: size / 2 + size / 16 + (index - 2) * size / 4,
      width: size / 8,
      height: size / 8,
      borderRadius: size / 16,
      backgroundColor: color,
      transform
    };
    if (index === count - 1) {
      transform.push({
        scale: progress.interpolate({
          inputRange: [0, 0.5],
          outputRange: [0, 1],
          extrapolate: "clamp"
        })
      });
      style.opacity = progress.interpolate({
        inputRange: [0, 0.25],
        outputRange: [0, 1],
        extrapolate: "clamp"
      });
    }
    return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
      style: style,
      key: index
    });
  }, [size, color]);
  const _renderComponent = _react.default.useCallback(({
    index,
    count,
    progress
  }) => {
    if (index > 1) {
      return _renderBlock({
        index,
        count,
        progress
      });
    }
    let hf = size / 2;
    let qr = size / 4;
    let pacmanStyle = {
      position: "absolute",
      top: qr,
      left: 0,
      width: hf,
      height: hf,
      transform: [{
        rotate: progress.interpolate({
          inputRange: [0, 0.67, 1],
          outputRange: index ^ _reactNative.I18nManager.isRTL ? ["0deg", "45deg", "0deg"] : ["0deg", "-45deg", "0deg"],
          extrapolate: "clamp"
        })
      }]
    };
    let containerStyle = {
      overflow: "hidden",
      width: hf,
      height: qr,
      ...(index ? {
        top: qr,
        borderBottomLeftRadius: qr,
        borderBottomRightRadius: qr
      } : {
        borderTopLeftRadius: qr,
        borderTopRightRadius: qr
      }),
      backgroundColor: color
    };
    return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
      style: pacmanStyle,
      key: index
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
      style: containerStyle
    }));
  }, [_renderBlock, size, color]);
  const {
    style,
    ...props
  } = rest;
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [{
      flex: 1,
      justifyContent: "center",
      alignItems: "center"
    }, style]
  }, /*#__PURE__*/_react.default.createElement(_indicator.default, _extends({}, props, {
    ref: ref,
    style: {
      width: size * 1.25,
      height: size
    },
    renderComponent: _renderComponent,
    count: 5
  })));
}));
var _default = exports.default = PacmanIndicator;
//# sourceMappingURL=pacman.js.map