import { onBeforeUnmount, ref, watch } from "vue";
import { SUPPORTS_INTERSECTION_OBSERVER } from "@veno-ui/utils";
function useIntersectionObserver(callback) {
  const intersectionRef = ref();
  const isIntersecting = ref(false);
  if (SUPPORTS_INTERSECTION_OBSERVER) {
    const observer = new IntersectionObserver((entries) => {
      callback?.(entries, observer);
      isIntersecting.value = !!entries.find((entry) => entry.isIntersecting);
    });
    onBeforeUnmount(() => {
      observer.disconnect();
    });
    watch(intersectionRef, (newValue, oldValue) => {
      if (oldValue) {
        observer.unobserve(oldValue);
        isIntersecting.value = false;
      }
      if (newValue)
        observer.observe(newValue);
    }, {
      flush: "post"
    });
  } else {
    isIntersecting.value = true;
  }
  return { intersectionRef, isIntersecting };
}
export {
  useIntersectionObserver
};
//# sourceMappingURL=index.mjs.map
