"use client";
import * as f from "react";
import { assignRef as o } from "./assignRef.js";
import { useCallbackRef as l } from "./useRef.js";
var s = typeof window < "u" ? f.useLayoutEffect : f.useEffect, c = /* @__PURE__ */ new WeakMap();
function v(a, m) {
  var t = l(null, function(n) {
    return a.forEach(function(u) {
      return o(u, n);
    });
  });
  return s(function() {
    var n = c.get(t);
    if (n) {
      var u = new Set(n), r = new Set(a), i = t.current;
      u.forEach(function(e) {
        r.has(e) || o(e, null);
      }), r.forEach(function(e) {
        u.has(e) || o(e, i);
      });
    }
    c.set(t, a);
  }, [a]), t;
}
export {
  v as useMergeRefs
};
