"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
const globals = require("../utils/globals.cjs");
const useContentMemo = require("./useContentMemo.cjs");
const useSSRLayoutEffect = require("./useSSRLayoutEffect.cjs");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
function useResizeObserver(callback, optionsInput, ref) {
  const observer = React__namespace.useRef();
  const options = useContentMemo.useContentMemo(optionsInput);
  const observe = React__namespace.useCallback((element) => {
    observer.current = new ResizeObserver(callback);
    observer.current.observe(element, options);
  }, [callback, options]);
  const unobserve = React__namespace.useCallback((element) => {
    if (observer.current) {
      observer.current.unobserve(element);
    }
  }, []);
  const disconnect = React__namespace.useCallback(() => {
    var _a;
    (_a = observer.current) == null ? void 0 : _a.disconnect();
  }, []);
  useSSRLayoutEffect.useSSRLayoutEffect(() => {
    if (!!(ref == null ? void 0 : ref.current) && globals.isBrowser && globals.supportsResizeObserver) {
      observe(ref.current);
      return () => {
        if (ref.current) {
          unobserve(ref.current);
        }
      };
    }
    return void 0;
  }, [observe, unobserve, ref]);
  React__namespace.useEffect(() => disconnect, [disconnect]);
  return {
    observer,
    unobserve,
    disconnect
  };
}
exports.useResizeObserver = useResizeObserver;
//# sourceMappingURL=useResizeObserver.cjs.map
