import { useRef as c } from "react";
const f = 10;
function Y(t, r) {
  return t > r && t > f ? "horizontal" : r > t && r > f ? "vertical" : "";
}
function z() {
  const t = c(0), r = c(0), e = c(0), o = c(0), u = c(0), s = c(0), n = c(""), h = () => n.current === "vertical", X = () => n.current === "horizontal", l = () => {
    e.current = 0, o.current = 0, u.current = 0, s.current = 0, n.current = "";
  };
  return {
    move: (i) => {
      const a = i.touches[0];
      e.current = a.clientX < 0 ? 0 : a.clientX - t.current, o.current = a.clientY - r.current, u.current = Math.abs(e.current), s.current = Math.abs(o.current), n.current || (n.current = Y(u.current, s.current));
    },
    start: (i) => {
      l(), t.current = i.touches[0].clientX, r.current = i.touches[0].clientY;
    },
    reset: l,
    startX: t,
    startY: r,
    deltaX: e,
    deltaY: o,
    offsetX: u,
    offsetY: s,
    direction: n,
    isVertical: h,
    isHorizontal: X
  };
}
export {
  z as useTouch
};
