import c from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as C from "react";
import { useState as v, useRef as m } from "react";
var O = 0.1, P = 0.01, i = 20, w = Math.pow(0.995, i);
function V(E, f) {
  var I = v(), S = c(I, 2), s = S[0], h = S[1], D = v(0), _ = c(D, 2), b = _[0], R = _[1], W = v(0), M = c(W, 2), x = M[0], X = M[1], Y = v(), p = c(Y, 2), l = p[0], L = p[1], d = m();
  function A(r) {
    var t = r.touches[0], a = t.screenX, n = t.screenY;
    h({
      x: a,
      y: n
    }), window.clearInterval(d.current);
  }
  function N(r) {
    if (s) {
      r.preventDefault();
      var t = r.touches[0], a = t.screenX, n = t.screenY;
      h({
        x: a,
        y: n
      });
      var e = a - s.x, o = n - s.y;
      f(e, o);
      var y = Date.now();
      R(y), X(y - b), L({
        x: e,
        y: o
      });
    }
  }
  function $() {
    if (s && (h(null), L(null), l)) {
      var r = l.x / x, t = l.y / x, a = Math.abs(r), n = Math.abs(t);
      if (Math.max(a, n) < O)
        return;
      var e = r, o = t;
      d.current = window.setInterval(function() {
        if (Math.abs(e) < P && Math.abs(o) < P) {
          window.clearInterval(d.current);
          return;
        }
        e *= w, o *= w, f(e * i, o * i);
      }, i);
    }
  }
  var T = m();
  function F(r) {
    var t = r.deltaX, a = r.deltaY, n = 0, e = Math.abs(t), o = Math.abs(a);
    e === o ? n = T.current === "x" ? t : a : e > o ? (n = t, T.current = "x") : (n = a, T.current = "y"), f(-n, -n) && r.preventDefault();
  }
  var u = m(null);
  u.current = {
    onTouchStart: A,
    onTouchMove: N,
    onTouchEnd: $,
    onWheel: F
  }, C.useEffect(function() {
    function r(e) {
      u.current.onTouchStart(e);
    }
    function t(e) {
      u.current.onTouchMove(e);
    }
    function a(e) {
      u.current.onTouchEnd(e);
    }
    function n(e) {
      u.current.onWheel(e);
    }
    return document.addEventListener("touchmove", t, {
      passive: !1
    }), document.addEventListener("touchend", a, {
      passive: !1
    }), E.current.addEventListener("touchstart", r, {
      passive: !1
    }), E.current.addEventListener("wheel", n), function() {
      document.removeEventListener("touchmove", t), document.removeEventListener("touchend", a);
    };
  }, []);
}
export {
  V as default
};
