import { o as I } from "./rolldown-runtime.js";
import { i as M } from "./vendor/react.js";
import { t as g } from "./useIsoLayoutEffect.js";
var r = /* @__PURE__ */ I(M()), _ = /* @__PURE__ */ r.createContext({
  register: () => {
  },
  unregister: () => {
  },
  subscribeMapChange: () => () => {
  },
  elementsRef: { current: [] },
  nextIndexRef: { current: 0 }
});
function F() {
  return r.useContext(_);
}
var O = /* @__PURE__ */ (function(t) {
  return t[t.None = 0] = "None", t[t.GuessFromOrder = 1] = "GuessFromOrder", t;
})({});
function S(t = {}) {
  const { label: c, metadata: a, textRef: l, indexGuessBehavior: L, index: u } = t, { register: m, unregister: x, subscribeMapChange: C, elementsRef: d, labelsRef: i, nextIndexRef: p } = F(), f = r.useRef(-1), [n, R] = r.useState(u ?? (L === O.GuessFromOrder ? () => {
    if (f.current === -1) {
      const e = p.current;
      p.current += 1, f.current = e;
    }
    return f.current;
  } : -1)), s = r.useRef(null), b = r.useCallback((e) => {
    if (s.current = e, n !== -1 && e !== null && (d.current[n] = e, i)) {
      const o = c !== void 0;
      i.current[n] = o ? c : l?.current?.textContent ?? e.textContent;
    }
  }, [
    n,
    d,
    i,
    c,
    l
  ]);
  return g(() => {
    if (u != null) return;
    const e = s.current;
    if (e)
      return m(e, a), () => {
        x(e);
      };
  }, [
    u,
    m,
    x,
    a
  ]), g(() => {
    if (u == null)
      return C((e) => {
        const o = s.current ? e.get(s.current)?.index : null;
        o != null && R(o);
      });
  }, [
    u,
    C,
    R
  ]), r.useMemo(() => ({
    ref: b,
    index: n
  }), [n, b]);
}
export {
  S as n,
  _ as r,
  O as t
};

//# sourceMappingURL=useCompositeListItem.js.map