// src/components/Popover/useAutoUpdate.ts
import { useEffect } from "react";
var useAutoUpdate = ({
  referenceRef,
  floatingRef,
  onUpdate,
  enabled
}) => {
  useEffect(() => {
    if (!enabled) return;
    const reference = referenceRef.current;
    const floating = floatingRef.current;
    const scrollOpts = {
      capture: true,
      passive: true
    };
    window.addEventListener("scroll", onUpdate, scrollOpts);
    window.addEventListener("resize", onUpdate, { passive: true });
    const observer = typeof ResizeObserver === "function" ? new ResizeObserver(onUpdate) : null;
    if (observer && reference) observer.observe(reference);
    if (observer && floating) observer.observe(floating);
    return () => {
      window.removeEventListener("scroll", onUpdate, scrollOpts);
      window.removeEventListener("resize", onUpdate);
      observer?.disconnect();
    };
  }, [enabled, onUpdate, referenceRef, floatingRef]);
};

export {
  useAutoUpdate
};
//# sourceMappingURL=chunk-K3ECDAUR.js.map
