"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const raf = require("../../../../utils/raf.js");
const index = require("../../../../../node_modules/@vueuse/core/index.js");
const Vue = require("vue");
const useGridTouch = (windowRef, states, scrollTo, estimatedTotalWidth, estimatedTotalHeight, parsedWidth, parsedHeight) => {
  const touchStartX = Vue.ref(0);
  const touchStartY = Vue.ref(0);
  let frameHandle;
  let deltaX = 0;
  let deltaY = 0;
  const handleTouchStart = (event) => {
    raf.cAF(frameHandle);
    touchStartX.value = event.touches[0].clientX;
    touchStartY.value = event.touches[0].clientY;
    deltaX = 0;
    deltaY = 0;
  };
  const handleTouchMove = (event) => {
    event.preventDefault();
    raf.cAF(frameHandle);
    deltaX += touchStartX.value - event.touches[0].clientX;
    deltaY += touchStartY.value - event.touches[0].clientY;
    touchStartX.value = event.touches[0].clientX;
    touchStartY.value = event.touches[0].clientY;
    frameHandle = raf.rAF(() => {
      const maxScrollLeft = estimatedTotalWidth.value - Vue.unref(parsedWidth);
      const maxScrollTop = estimatedTotalHeight.value - Vue.unref(parsedHeight);
      scrollTo({
        scrollLeft: Math.min(states.value.scrollLeft + deltaX, maxScrollLeft),
        scrollTop: Math.min(states.value.scrollTop + deltaY, maxScrollTop)
      });
      deltaX = 0;
      deltaY = 0;
    });
  };
  index.useEventListener(windowRef, "touchstart", handleTouchStart, { passive: true });
  index.useEventListener(windowRef, "touchmove", handleTouchMove, { passive: false });
  return {
    touchStartX,
    touchStartY,
    handleTouchStart,
    handleTouchMove
  };
};
exports.useGridTouch = useGridTouch;
