import { c } from "react/compiler-runtime";
import { useCallback, useEffect, useRef, useState } from "react";
const useIntersectionObserver = (o) => {
	let l = c(7), u = o === void 0 ? "0px" : o, [d, f] = useState(null), p = useRef(null), m;
	l[0] === Symbol.for("react.memo_cache_sentinel") ? (m = /* @__PURE__ */ new Map(), l[0] = m) : m = l[0];
	let h = useRef(m), g, _;
	l[1] === u ? (g = l[2], _ = l[3]) : (g = () => {
		let e = h.current;
		return p.current = new IntersectionObserver((o) => {
			o.forEach((o) => {
				o.target.getAttribute("data-id") && (o.isIntersecting ? e.set(o.target, !0) : e.set(o.target, !1));
			});
			let s = Array.from(e.entries()).filter(_temp).map(_temp2).filter(_temp3).sort();
			s.length && f(s[0]);
		}, {
			root: document.querySelector(".list-container"),
			threshold: .05,
			rootMargin: u
		}), () => {
			p.current?.disconnect(), e.clear();
		};
	}, _ = [u], l[1] = u, l[2] = g, l[3] = _), useEffect(g, _);
	let v;
	l[4] === Symbol.for("react.memo_cache_sentinel") ? (v = (e) => {
		e && p.current?.observe(e);
	}, l[4] = v) : v = l[4];
	let y = v, b;
	return l[5] === d ? b = l[6] : (b = {
		activeId: d,
		observe: y
	}, l[5] = d, l[6] = b), b;
};
function _temp(e) {
	let [, o] = e;
	return o;
}
function _temp2(e) {
	let [o] = e;
	return o.getAttribute("data-id");
}
function _temp3(e) {
	return e !== null;
}
export { useIntersectionObserver };
