"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Popover/useAutoUpdate.ts
var useAutoUpdate_exports = {};
__export(useAutoUpdate_exports, {
  useAutoUpdate: () => useAutoUpdate
});
module.exports = __toCommonJS(useAutoUpdate_exports);
var import_react = require("react");
var useAutoUpdate = ({
  referenceRef,
  floatingRef,
  onUpdate,
  enabled
}) => {
  (0, import_react.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]);
};
//# sourceMappingURL=useAutoUpdate.js.map
