{"version":3,"file":"useInfiniteScroll.cjs","sources":["../../../../components/data-view/hooks/useInfiniteScroll.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\n\ninterface UseInfiniteScrollParams {\n  /** When false, no observer is attached. */\n  enabled: boolean;\n  /** Sentinel element observed near the end of the list. */\n  sentinelRef: React.RefObject<Element | null>;\n  /** Scroll container used as the IntersectionObserver root. */\n  scrollRef: React.RefObject<Element | null>;\n  /** Suppresses the trigger while a previous fetch is in flight. */\n  isLoading?: boolean;\n  /** Fires when the sentinel intersects the root viewport. */\n  onLoadMore?: () => void;\n  /**\n   * Distance past the bottom edge that still counts as \"near the end\". The\n   * sentinel fires once the user scrolls within this many pixels of it.\n   * Default 200.\n   */\n  rootMargin?: number;\n}\n\n/**\n * Single sentinel-based load-more. Used by both virtualized and non-virtualized\n * renderers so behaviour stays identical regardless of the row model.\n *\n * The sentinel itself is a sibling rendered after the rows by the caller; this\n * hook only attaches the observer. `isLoading` and `onLoadMore` are tracked\n * through refs so the observer doesn't re-attach on every render.\n */\nexport function useInfiniteScroll({\n  enabled,\n  sentinelRef,\n  scrollRef,\n  isLoading,\n  onLoadMore,\n  rootMargin = 200\n}: UseInfiniteScrollParams) {\n  const onLoadMoreRef = useRef(onLoadMore);\n  const isLoadingRef = useRef(isLoading);\n\n  onLoadMoreRef.current = onLoadMore;\n  isLoadingRef.current = isLoading;\n\n  useEffect(() => {\n    if (!enabled) return;\n    const sentinel = sentinelRef.current;\n    if (!sentinel) return;\n\n    const root = scrollRef.current ?? null;\n\n    const observer = new IntersectionObserver(\n      entries => {\n        const entry = entries[0];\n        if (!entry?.isIntersecting) return;\n        if (isLoadingRef.current) return;\n        onLoadMoreRef.current?.();\n      },\n      {\n        root,\n        rootMargin: `0px 0px ${rootMargin}px 0px`,\n        threshold: 0\n      }\n    );\n\n    observer.observe(sentinel);\n    return () => observer.disconnect();\n    // sentinelRef/scrollRef are stable refs; re-attach only when enable flips.\n  }, [enabled, rootMargin, sentinelRef, scrollRef]);\n}\n"],"names":[],"mappings":";;;;;AAuBA;;;;;;;AAOG;;AASD;AACA;AAEA;AACA;;AAGE;;AACA;AACA;;AAEA;AAEA;AAEI;;;;;AAGA;AACF;;;AAIE;AACD;AAGH;AACA;;;AAGJ;;"}