// packages/block-editor/src/components/block-popover/use-popover-scroll.js
import { useRefEffect } from "@wordpress/compose";
import { getScrollContainer } from "@wordpress/dom";
var scrollContainerCache = /* @__PURE__ */ new WeakMap();
function usePopoverScroll(contentRef) {
  const effect = useRefEffect(
    (node) => {
      function onWheel(event) {
        const { deltaX, deltaY, target } = event;
        const contentEl = contentRef.current;
        let scrollContainer = scrollContainerCache.get(contentEl);
        if (!scrollContainer) {
          scrollContainer = getScrollContainer(contentEl);
          scrollContainerCache.set(contentEl, scrollContainer);
        }
        const eventScrollContainer = getScrollContainer(target);
        if (!node.contains(eventScrollContainer)) {
          scrollContainer.scrollBy(deltaX, deltaY);
        }
      }
      const options = { passive: true };
      node.addEventListener("wheel", onWheel, options);
      return () => {
        node.removeEventListener("wheel", onWheel, options);
      };
    },
    [contentRef]
  );
  return contentRef ? effect : null;
}
var use_popover_scroll_default = usePopoverScroll;
export {
  use_popover_scroll_default as default
};
//# sourceMappingURL=use-popover-scroll.js.map
