{"version":3,"file":"useStickyGroupAnchor.cjs","sources":["../../../../components/data-table/hooks/useStickyGroupAnchor.tsx"],"sourcesContent":["import { useCallback, useLayoutEffect, useState } from 'react';\nimport { GroupedData } from '../data-table.types';\n\ninterface UseStickyGroupAnchorParams<TData> {\n  enabled: boolean;\n  groupHeaderList: {\n    index: number;\n    start: number;\n    data: GroupedData<TData>;\n  }[];\n  scrollContainerRef: React.RefObject<HTMLDivElement | null>;\n}\n\ninterface UseStickyGroupAnchorResult<TData> {\n  stickyGroup: GroupedData<TData> | null;\n  stickyGroupIndex: number | null;\n  recompute: () => void;\n}\n\n/**\n * Tracks the active group for the virtualized sticky group anchor.\n *\n * Picks the latest group whose `start` offset has been scrolled past, so the\n * anchor's content stays in sync with the natural section header underneath.\n *\n * Returns the current group's data plus the row index of its natural section\n * header — the consumer hides that row in the virtualized body so the natural\n * header doesn't visually slide past the anchor (matching the non-virtualized\n * table where CSS sticky pins each section header at the offset).\n *\n * `start` is supplied by the caller (computed from row sizes) rather than read\n * from the virtualizer's measurements cache, so it stays correct across data\n * loads even before the virtualizer has measured shifted rows.\n */\nexport function useStickyGroupAnchor<TData>({\n  enabled,\n  groupHeaderList,\n  scrollContainerRef\n}: UseStickyGroupAnchorParams<TData>): UseStickyGroupAnchorResult<TData> {\n  const [stickyGroup, setStickyGroup] = useState<GroupedData<TData> | null>(\n    null\n  );\n  const [stickyGroupIndex, setStickyGroupIndex] = useState<number | null>(null);\n\n  const recompute = useCallback(() => {\n    if (!enabled || groupHeaderList.length === 0) {\n      setStickyGroup(null);\n      setStickyGroupIndex(null);\n      return;\n    }\n    const el = scrollContainerRef.current;\n    if (!el) return;\n    const scrollTop = el.scrollTop;\n\n    let currentIdx = -1;\n    for (let i = 0; i < groupHeaderList.length; i++) {\n      if (groupHeaderList[i].start <= scrollTop) {\n        currentIdx = i;\n      } else {\n        break;\n      }\n    }\n\n    if (currentIdx < 0) {\n      setStickyGroup(null);\n      setStickyGroupIndex(null);\n      return;\n    }\n\n    setStickyGroup(groupHeaderList[currentIdx].data);\n    setStickyGroupIndex(groupHeaderList[currentIdx].index);\n  }, [enabled, groupHeaderList, scrollContainerRef]);\n\n  useLayoutEffect(() => {\n    recompute();\n  }, [recompute]);\n\n  return { stickyGroup, stickyGroupIndex, recompute };\n}\n"],"names":["useState","useCallback","useLayoutEffect"],"mappings":";;;;AAmBA;;;;;;;;;;;;;;AAcG;AACG,SAAU,oBAAoB,CAAQ,EAC1C,OAAO,EACP,eAAe,EACf,kBAAkB,EACgB,EAAA;IAClC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAGA,cAAQ,CAC5C,IAAI,CACL,CAAC;IACF,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAGA,cAAQ,CAAgB,IAAI,CAAC,CAAC;AAE9E,IAAA,MAAM,SAAS,GAAGC,iBAAW,CAAC,MAAK;QACjC,IAAI,CAAC,OAAO,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5C,cAAc,CAAC,IAAI,CAAC,CAAC;YACrB,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAC1B,OAAO;SACR;AACD,QAAA,MAAM,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC;AACtC,QAAA,IAAI,CAAC,EAAE;YAAE,OAAO;AAChB,QAAA,MAAM,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC;AAE/B,QAAA,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;AACpB,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,SAAS,EAAE;gBACzC,UAAU,GAAG,CAAC,CAAC;aAChB;iBAAM;gBACL,MAAM;aACP;SACF;AAED,QAAA,IAAI,UAAU,GAAG,CAAC,EAAE;YAClB,cAAc,CAAC,IAAI,CAAC,CAAC;YACrB,mBAAmB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