"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
function useInViewport() {
  const observer = React.useRef(null);
  const [inViewport, setInViewport] = React.useState(false);
  const ref = React.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 };
}
exports.useInViewport = useInViewport;
