var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/PisellScrollView/hooks/useIntersection.ts
var useIntersection_exports = {};
__export(useIntersection_exports, {
  useIntersection: () => useIntersection
});
module.exports = __toCommonJS(useIntersection_exports);
var import_react = require("react");
var useIntersection = ({ containerRef, config }) => {
  (0, import_react.useEffect)(() => {
    if (!(config == null ? void 0 : config.enabled) || !containerRef.current) return;
    const {
      threshold = 0,
      rootMargin = "0px",
      targetSelector,
      onEnterViewport,
      onLeaveViewport,
      onVisibilityChange
    } = config;
    const container = containerRef.current;
    const targets = targetSelector ? container.querySelectorAll(targetSelector) : container.children;
    if (!targets || targets.length === 0) return;
    const observer = new IntersectionObserver(
      (entries) => {
        entries.forEach((entry) => {
          const element = entry.target;
          onVisibilityChange == null ? void 0 : onVisibilityChange(entry, element);
          if (entry.isIntersecting) {
            onEnterViewport == null ? void 0 : onEnterViewport(entry, element);
          } else {
            onLeaveViewport == null ? void 0 : onLeaveViewport(entry, element);
          }
        });
      },
      {
        root: container,
        rootMargin,
        threshold
      }
    );
    Array.from(targets).forEach((target) => observer.observe(target));
    return () => {
      observer.disconnect();
    };
  }, [config, containerRef]);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useIntersection
});
