"use strict";

exports.__esModule = true;
exports.useCloseOnAncestorScroll = useCloseOnAncestorScroll;
var _react = require("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.
 */
function useCloseOnAncestorScroll(wrapperRef, closePopover, enabled) {
  (0, _react.useEffect)(() => {
    if (!enabled) {
      return;
    }
    const onScroll = e => {
      const target = e.target;
      if (target.contains != null && target.contains(wrapperRef.current)) {
        closePopover();
      }
    };
    document.addEventListener('scroll', onScroll, true);
    return () => document.removeEventListener('scroll', onScroll, true);
  }, [wrapperRef, closePopover, enabled]);
}
//# sourceMappingURL=useCloseOnAncestorScroll.js.map