"use client";
import { t as e } from "./useIsoLayoutEffect-CKOv1bV_.js";
import * as t from "react";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/internals/composite/list/CompositeListContext.js
var n = /*#__PURE__*/ t.createContext({
	register: () => {},
	unregister: () => {},
	subscribeMapChange: () => () => {},
	elementsRef: { current: [] },
	nextIndexRef: { current: 0 }
});
process.env.NODE_ENV !== "production" && (n.displayName = "CompositeListContext");
function r() {
	return t.useContext(n);
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/internals/composite/list/useCompositeListItem.js
var i = /*#__PURE__*/ function(e) {
	return e[e.None = 0] = "None", e[e.GuessFromOrder = 1] = "GuessFromOrder", e;
}({});
function a(n = {}) {
	let { label: a, metadata: o, textRef: s, indexGuessBehavior: c, index: l } = n, { register: u, unregister: d, subscribeMapChange: f, elementsRef: p, labelsRef: m, nextIndexRef: h } = r(), g = t.useRef(-1), [_, v] = t.useState(l ?? (c === i.GuessFromOrder ? () => {
		if (g.current === -1) {
			let e = h.current;
			h.current += 1, g.current = e;
		}
		return g.current;
	} : -1)), y = t.useRef(null), b = t.useCallback((e) => {
		if (y.current = e, _ !== -1 && e !== null && (p.current[_] = e, m)) {
			let t = a !== void 0;
			m.current[_] = t ? a : s?.current?.textContent ?? e.textContent;
		}
	}, [
		_,
		p,
		m,
		a,
		s
	]);
	return e(() => {
		if (l != null) return;
		let e = y.current;
		if (e) return u(e, o), () => {
			d(e);
		};
	}, [
		l,
		u,
		d,
		o
	]), e(() => {
		if (l == null) return f((e) => {
			let t = y.current ? e.get(y.current)?.index : null;
			t != null && v(t);
		});
	}, [
		l,
		f,
		v
	]), t.useMemo(() => ({
		ref: b,
		index: _
	}), [_, b]);
}
//#endregion
export { a as n, n as r, i as t };
