import n from "react";
import { createContextScope as O } from "../../../../../@radix-ui_react-context@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-context/dist/index.js";
import { useComposedRefs as I } from "../../../../../@radix-ui_react-compose-refs@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { Slot as S } from "../../../../../@radix-ui_react-slot@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-slot/dist/index.js";
import { j as u } from "../../../../../../../_virtual/jsx-runtime.js";
function L(s) {
  const f = s + "CollectionProvider", [A, E] = O(f), [N, m] = A(
    f,
    { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
  ), a = (c) => {
    const { scope: e, children: l } = c, o = n.useRef(null), t = n.useRef(/* @__PURE__ */ new Map()).current;
    return /* @__PURE__ */ u.jsx(N, { scope: e, itemMap: t, collectionRef: o, children: l });
  };
  a.displayName = f;
  const d = s + "CollectionSlot", p = n.forwardRef(
    (c, e) => {
      const { scope: l, children: o } = c, t = m(d, l), r = I(e, t.collectionRef);
      return /* @__PURE__ */ u.jsx(S, { ref: r, children: o });
    }
  );
  p.displayName = d;
  const C = s + "CollectionItemSlot", R = "data-radix-collection-item", x = n.forwardRef(
    (c, e) => {
      const { scope: l, children: o, ...t } = c, r = n.useRef(null), M = I(e, r), i = m(C, l);
      return n.useEffect(() => (i.itemMap.set(r, { ref: r, ...t }), () => void i.itemMap.delete(r))), /* @__PURE__ */ u.jsx(S, { [R]: "", ref: M, children: o });
    }
  );
  x.displayName = C;
  function _(c) {
    const e = m(s + "CollectionConsumer", c);
    return n.useCallback(() => {
      const o = e.collectionRef.current;
      if (!o) return [];
      const t = Array.from(o.querySelectorAll(`[${R}]`));
      return Array.from(e.itemMap.values()).sort(
        (i, T) => t.indexOf(i.ref.current) - t.indexOf(T.ref.current)
      );
    }, [e.collectionRef, e.itemMap]);
  }
  return [
    { Provider: a, Slot: p, ItemSlot: x },
    _,
    E
  ];
}
export {
  L as createCollection
};
//# sourceMappingURL=index.js.map
