"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SpotCutout = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeSvg = require("react-native-svg");
var _tourContext = require("../../contexts/tour/tour-context");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const AnimatedRectangle = _reactNative.Animated.createAnimatedComponent(_reactNativeSvg.Rect);
const SpotCutout = () => {
  const {
    spot
  } = (0, _react.useContext)(_tourContext.TourContext);
  const spotPadding = 20;
  const start = (0, _react.useRef)(new _reactNative.Animated.ValueXY({
    x: 0,
    y: 0
  }));
  const width = (0, _react.useRef)(new _reactNative.Animated.Value(0));
  const height = (0, _react.useRef)(new _reactNative.Animated.Value(0));
  (0, _react.useEffect)(() => {
    const {
      height: spotHeight,
      width: spotWidth,
      x,
      y
    } = spot;
    const w = spotWidth + spotPadding;
    const h = spotHeight + spotPadding;
    const paddedX = x - spotPadding / 2;
    const paddedY = y - spotPadding / 2;
    const transition = () => {
      return _reactNative.Animated.parallel([_reactNative.Animated.timing(start.current, {
        duration: 500,
        easing: _reactNative.Easing.out(_reactNative.Easing.exp),
        toValue: {
          x: paddedX,
          y: paddedY
        },
        useNativeDriver: false
      }), _reactNative.Animated.timing(width.current, {
        duration: 500,
        easing: _reactNative.Easing.out(_reactNative.Easing.exp),
        toValue: w,
        useNativeDriver: false
      }), _reactNative.Animated.timing(height.current, {
        duration: 500,
        easing: _reactNative.Easing.out(_reactNative.Easing.exp),
        toValue: h,
        useNativeDriver: false
      })]);
    };
    transition().start();
  }, [spot.height, spot.width, spot.x, spot.y]);
  if ([spot.height, spot.width].every(value => value <= 0)) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(AnimatedRectangle, {
    width: width.current,
    height: height.current,
    x: start.current.x,
    y: start.current.y,
    opacity: 1,
    rx: 10,
    fill: "black"
  });
};
exports.SpotCutout = SpotCutout;
//# sourceMappingURL=SpotCutout.js.map