import { __spreadArray as x } from "../../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
import * as n from "react";
import { RemoveScrollBar as A } from "../../../../../react-remove-scroll-bar@2.3.8_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-remove-scroll-bar/dist/es2015/component.js";
import { styleSingleton as I } from "../../../../../react-style-singleton@2.2.3_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-style-singleton/dist/es2015/component.js";
import { nonPassive as s } from "./aggresiveCapture.js";
import { locationCouldBeScrolled as T, handleScroll as W } from "./handleScroll.js";
var k = function(t) {
  return "changedTouches" in t ? [t.changedTouches[0].clientX, t.changedTouches[0].clientY] : [0, 0];
}, Y = function(t) {
  return [t.deltaX, t.deltaY];
}, B = function(t) {
  return t && "current" in t ? t.current : t;
}, F = function(t, c) {
  return t[0] === c[0] && t[1] === c[1];
}, O = function(t) {
  return `
  .block-interactivity-`.concat(t, ` {pointer-events: none;}
  .allow-interactivity-`).concat(t, ` {pointer-events: all;}
`);
}, Q = 0, f = [];
function G(t) {
  var c = n.useRef([]), E = n.useRef([0, 0]), d = n.useRef(), v = n.useState(Q++)[0], m = n.useState(I)[0], g = n.useRef(t);
  n.useEffect(function() {
    g.current = t;
  }, [t]), n.useEffect(function() {
    if (t.inert) {
      document.body.classList.add("block-interactivity-".concat(v));
      var e = x([t.lockRef.current], (t.shards || []).map(B), !0).filter(Boolean);
      return e.forEach(function(r) {
        return r.classList.add("allow-interactivity-".concat(v));
      }), function() {
        document.body.classList.remove("block-interactivity-".concat(v)), e.forEach(function(r) {
          return r.classList.remove("allow-interactivity-".concat(v));
        });
      };
    }
  }, [t.inert, t.lockRef.current, t.shards]);
  var y = n.useCallback(function(e, r) {
    if ("touches" in e && e.touches.length === 2)
      return !g.current.allowPinchZoom;
    var l = k(e), o = E.current, u = "deltaX" in e ? e.deltaX : o[0] - l[0], i = "deltaY" in e ? e.deltaY : o[1] - l[1], a, C = e.target, h = Math.abs(u) > Math.abs(i) ? "h" : "v";
    if ("touches" in e && h === "h" && C.type === "range")
      return !1;
    var b = T(h, C);
    if (!b)
      return !0;
    if (b ? a = h : (a = h === "v" ? "h" : "v", b = T(h, C)), !b)
      return !1;
    if (!d.current && "changedTouches" in e && (u || i) && (d.current = a), !a)
      return !0;
    var P = d.current || a;
    return W(P, r, e, P === "h" ? u : i);
  }, []), S = n.useCallback(function(e) {
    var r = e;
    if (!(!f.length || f[f.length - 1] !== m)) {
      var l = "deltaY" in r ? Y(r) : k(r), o = c.current.filter(function(a) {
        return a.name === r.type && (a.target === r.target || r.target === a.shadowParent) && F(a.delta, l);
      })[0];
      if (o && o.should) {
        r.cancelable && r.preventDefault();
        return;
      }
      if (!o) {
        var u = (g.current.shards || []).map(B).filter(Boolean).filter(function(a) {
          return a.contains(r.target);
        }), i = u.length > 0 ? y(r, u[0]) : !g.current.noIsolation;
        i && r.cancelable && r.preventDefault();
      }
    }
  }, []), R = n.useCallback(function(e, r, l, o) {
    var u = { name: e, delta: r, target: l, should: o, shadowParent: Z(l) };
    c.current.push(u), setTimeout(function() {
      c.current = c.current.filter(function(i) {
        return i !== u;
      });
    }, 1);
  }, []), w = n.useCallback(function(e) {
    E.current = k(e), d.current = void 0;
  }, []), L = n.useCallback(function(e) {
    R(e.type, Y(e), e.target, y(e, t.lockRef.current));
  }, []), M = n.useCallback(function(e) {
    R(e.type, k(e), e.target, y(e, t.lockRef.current));
  }, []);
  n.useEffect(function() {
    return f.push(m), t.setCallbacks({
      onScrollCapture: L,
      onWheelCapture: L,
      onTouchMoveCapture: M
    }), document.addEventListener("wheel", S, s), document.addEventListener("touchmove", S, s), document.addEventListener("touchstart", w, s), function() {
      f = f.filter(function(e) {
        return e !== m;
      }), document.removeEventListener("wheel", S, s), document.removeEventListener("touchmove", S, s), document.removeEventListener("touchstart", w, s);
    };
  }, []);
  var X = t.removeScrollBar, D = t.inert;
  return n.createElement(
    n.Fragment,
    null,
    D ? n.createElement(m, { styles: O(v) }) : null,
    X ? n.createElement(A, { gapMode: t.gapMode }) : null
  );
}
function Z(t) {
  for (var c = null; t !== null; )
    t instanceof ShadowRoot && (c = t.host, t = t.host), t = t.parentNode;
  return c;
}
export {
  G as RemoveScrollSideCar,
  Y as getDeltaXY,
  k as getTouchXY
};
//# sourceMappingURL=SideEffect.js.map
