import r from "react";
import { c as y } from "./index-DOfn3ixy.mjs";
import { u as M } from "./index-DLcqcWxM.mjs";
import { c as x } from "./index-CCNZ9uWB.mjs";
import { jsx as d } from "react/jsx-runtime";
function g(s) {
  const m = s + "CollectionProvider", [A, N] = y(m), [_, f] = A(
    m,
    { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
  ), p = (c) => {
    const { scope: e, children: l } = c, o = r.useRef(null), t = r.useRef(/* @__PURE__ */ new Map()).current;
    return /* @__PURE__ */ d(_, { scope: e, itemMap: t, collectionRef: o, children: l });
  };
  p.displayName = m;
  const a = s + "CollectionSlot", E = x(a), C = r.forwardRef(
    (c, e) => {
      const { scope: l, children: o } = c, t = f(a, l), n = M(e, t.collectionRef);
      return /* @__PURE__ */ d(E, { ref: n, children: o });
    }
  );
  C.displayName = a;
  const u = s + "CollectionItemSlot", R = "data-radix-collection-item", T = x(u), I = r.forwardRef(
    (c, e) => {
      const { scope: l, children: o, ...t } = c, n = r.useRef(null), S = M(e, n), i = f(u, l);
      return r.useEffect(() => (i.itemMap.set(n, { ref: n, ...t }), () => {
        i.itemMap.delete(n);
      })), /* @__PURE__ */ d(T, { [R]: "", ref: S, children: o });
    }
  );
  I.displayName = u;
  function O(c) {
    const e = f(s + "CollectionConsumer", c);
    return r.useCallback(() => {
      const o = e.collectionRef.current;
      if (!o) return [];
      const t = Array.from(o.querySelectorAll(`[${R}]`));
      return Array.from(e.itemMap.values()).sort(
        (i, v) => t.indexOf(i.ref.current) - t.indexOf(v.ref.current)
      );
    }, [e.collectionRef, e.itemMap]);
  }
  return [
    { Provider: p, Slot: C, ItemSlot: I },
    O,
    N
  ];
}
export {
  g as c
};
//# sourceMappingURL=index-MiRhI3nq.mjs.map
