"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AttachTourStep = AttachTourStep;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _tourContext = require("../../contexts/tour/tour-context");
var _testable = require("../../utils/testable");
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; }
/**
 * React functional component used to attach and step to another component by
 * only wrapping it. Use its props to customize the behavior.
 *
 * @param props the component props
 * @returns an AttachTourStep React element
 */
function AttachTourStep(_ref) {
  var _children$props;
  let {
    children,
    fill = false,
    index,
    tourID
  } = _ref;
  const {
    currentStep,
    currentTour,
    changeSpot
  } = (0, _react.useContext)(_tourContext.TourContext);
  const childRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(() => {
    if (currentTour === tourID && currentStep === index) {
      var _childRef$current;
      (_childRef$current = childRef.current) === null || _childRef$current === void 0 ? void 0 : _childRef$current.measureInWindow((x, y, width, height) => {
        changeSpot({
          height,
          width,
          x,
          y
        });
      });
    }
  }, [changeSpot, currentTour, currentStep, index]);
  const {
    style,
    ...rest
  } = children.props;
  const childStyle = style ?? {};
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    testID: (0, _testable.testIdWithKey)('AttachTourStep'),
    ref: childRef,
    style: {
      alignSelf: fill ? 'stretch' : 'center',
      ...childStyle
    },
    collapsable: false,
    focusable: false
  }, /*#__PURE__*/(0, _react.cloneElement)(children, rest, (_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props.children));
}
//# sourceMappingURL=AttachTourStep.js.map