import { useState } from 'react';

const useSwipe = (func) => {
  const [direction, setDirection] = useState(null);
  const [touchStart, setTouchStart] = useState(null);
  const [touchEnd, setTouchEnd] = useState(null);
  const minSwipeDistance = 50;
  const onTouchMove = (e) => setTouchEnd(e.targetTouches[0].clientX);
  const onTouchEnd = (_e) => {
    if (!touchStart || !touchEnd) return;
    const distance = touchStart - touchEnd;
    const isLeftSwipe = distance > minSwipeDistance;
    const isRightSwipe = distance < -minSwipeDistance;
    let dir = null;
    if (isLeftSwipe) dir = "left";
    if (isRightSwipe) dir = "right";
    func?.(dir);
    setDirection(dir);
  };
  const onTouchStart = (e) => {
    setTouchEnd(null);
    setTouchStart(e.targetTouches[0].clientX);
  };
  return { onTouchMove, onTouchEnd, onTouchStart, direction };
};

export { useSwipe as u };
//# sourceMappingURL=useSwipe-Cp-CJxLU.js.map
