import { t as e } from "./useIsoLayoutEffect-CKOv1bV_.js";
import { f as t } from "./useRenderElement-CmuWsiNa.js";
import { t as n } from "./useStableCallback-CqEVb76s.js";
import { r } from "./useCompositeListItem-xM6vOR9-.js";
import * as i from "react";
import { jsx as a } from "react/jsx-runtime";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/internals/composite/list/CompositeList.js
function o(o) {
	let { children: u, elementsRef: d, labelsRef: f, onMapChange: p } = o, m = n(p), h = i.useRef(0), g = t(c).current, _ = t(s).current, [v, y] = i.useState(0), b = i.useRef(v), x = n((e, t) => {
		_.set(e, t ?? null), b.current += 1, y(b.current);
	}), S = n((e) => {
		_.delete(e), b.current += 1, y(b.current);
	}), C = i.useMemo(() => {
		let e = /* @__PURE__ */ new Map();
		return Array.from(_.keys()).filter((e) => e.isConnected).sort(l).forEach((t, n) => {
			let r = _.get(t) ?? {};
			e.set(t, {
				...r,
				index: n
			});
		}), e;
	}, [_, v]);
	e(() => {
		if (typeof MutationObserver != "function" || C.size === 0) return;
		let e = new MutationObserver((e) => {
			let t = /* @__PURE__ */ new Set(), n = (e) => t.has(e) ? t.delete(e) : t.add(e);
			e.forEach((e) => {
				e.removedNodes.forEach(n), e.addedNodes.forEach(n);
			}), t.size === 0 && (b.current += 1, y(b.current));
		});
		return C.forEach((t, n) => {
			n.parentElement && e.observe(n.parentElement, { childList: !0 });
		}), () => {
			e.disconnect();
		};
	}, [C]), e(() => {
		b.current === v && (d.current.length !== C.size && (d.current.length = C.size), f && f.current.length !== C.size && (f.current.length = C.size), h.current = C.size), m(C);
	}, [
		m,
		C,
		d,
		f,
		v
	]), e(() => () => {
		d.current = [];
	}, [d]), e(() => () => {
		f && (f.current = []);
	}, [f]);
	let w = n((e) => (g.add(e), () => {
		g.delete(e);
	}));
	e(() => {
		g.forEach((e) => e(C));
	}, [g, C]);
	let T = i.useMemo(() => ({
		register: x,
		unregister: S,
		subscribeMapChange: w,
		elementsRef: d,
		labelsRef: f,
		nextIndexRef: h
	}), [
		x,
		S,
		w,
		d,
		f,
		h
	]);
	return /*#__PURE__*/ a(r.Provider, {
		value: T,
		children: u
	});
}
function s() {
	return /* @__PURE__ */ new Map();
}
function c() {
	return /* @__PURE__ */ new Set();
}
function l(e, t) {
	let n = e.compareDocumentPosition(t);
	return n & Node.DOCUMENT_POSITION_FOLLOWING || n & Node.DOCUMENT_POSITION_CONTAINED_BY ? -1 : n & Node.DOCUMENT_POSITION_PRECEDING || n & Node.DOCUMENT_POSITION_CONTAINS ? 1 : 0;
}
//#endregion
export { o as t };
