"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
const MotionConfigContext = require("../context/MotionConfigContext.js");
const useUnmountEffect = require("../utils/use-unmount-effect.js");
const usePointerEvent = require("../events/use-pointer-event.js");
const PanSession = require("./PanSession.js");
function usePanGesture(_a) {
  var onPan = _a.onPan, onPanStart = _a.onPanStart, onPanEnd = _a.onPanEnd, onPanSessionStart = _a.onPanSessionStart, visualElement = _a.visualElement;
  var hasPanEvents = onPan || onPanStart || onPanEnd || onPanSessionStart;
  var panSession = React.useRef(null);
  var transformPagePoint = React.useContext(MotionConfigContext.MotionConfigContext).transformPagePoint;
  var handlers = {
    onSessionStart: onPanSessionStart,
    onStart: onPanStart,
    onMove: onPan,
    onEnd: function(event, info) {
      panSession.current = null;
      onPanEnd && onPanEnd(event, info);
    }
  };
  React.useEffect(function() {
    if (panSession.current !== null) {
      panSession.current.updateHandlers(handlers);
    }
  });
  function onPointerDown(event) {
    panSession.current = new PanSession.PanSession(event, handlers, {
      transformPagePoint
    });
  }
  usePointerEvent.usePointerEvent(visualElement, "pointerdown", hasPanEvents && onPointerDown);
  useUnmountEffect.useUnmountEffect(function() {
    return panSession.current && panSession.current.end();
  });
}
exports.usePanGesture = usePanGesture;
//# sourceMappingURL=use-pan-gesture.js.map
