import { useRef, useState, useCallback } from "react";
function useInViewport() {
  const observer = useRef(null);
  const [inViewport, setInViewport] = useState(false);
  const ref = useCallback((node) => {
    var _a, _b;
    if (typeof IntersectionObserver !== "undefined") {
      if (node && !observer.current) {
        observer.current = new IntersectionObserver(
          ([entry]) => setInViewport(entry.isIntersecting)
        );
      } else {
        (_a = observer.current) == null ? void 0 : _a.disconnect();
      }
      if (node) {
        (_b = observer.current) == null ? void 0 : _b.observe(node);
      } else {
        setInViewport(false);
      }
    }
  }, []);
  return { ref, inViewport };
}
export {
  useInViewport
};
