import { useRef as c, useCallback as f, useEffect as b } from "react";
function L() {
  let o = c(/* @__PURE__ */ new Map()), u = f((e, l, r, t) => {
    let n = t != null && t.once ? (...d) => {
      o.current.delete(r), r(...d);
    } : r;
    o.current.set(r, {
      type: l,
      eventTarget: e,
      fn: n,
      options: t
    }), e.addEventListener(l, n, t);
  }, []), a = f((e, l, r, t) => {
    var n;
    let d = ((n = o.current.get(r)) === null || n === void 0 ? void 0 : n.fn) || r;
    e.removeEventListener(l, d, t), o.current.delete(r);
  }, []), s = f(() => {
    o.current.forEach((e, l) => {
      a(e.eventTarget, e.type, l, e.options);
    });
  }, [
    a
  ]);
  return b(() => s, [
    s
  ]), {
    addGlobalListener: u,
    removeGlobalListener: a,
    removeAllGlobalListeners: s
  };
}
export {
  L as useGlobalListeners
};
