import { useEffect } from 'react';
/**
 * Closes a popover when an ancestor element scrolls.
 * Ignores scroll events from within the component itself or its portaled content.
 * Only active when `enabled` is true — pass false when the cell isn't editing
 * to avoid a capture-phase scroll listener firing on every virtual-scroll frame.
 */
export function useCloseOnAncestorScroll(wrapperRef, closePopover, enabled) {
    useEffect(() => {
        if (!enabled) {
            return;
        }
        const onScroll = (e) => {
            const target = e.target;
            if (target.contains?.(wrapperRef.current)) {
                closePopover();
            }
        };
        document.addEventListener('scroll', onScroll, true);
        return () => document.removeEventListener('scroll', onScroll, true);
    }, [wrapperRef, closePopover, enabled]);
}
//# sourceMappingURL=useCloseOnAncestorScroll.js.map