import { o as c } from "./rolldown-runtime.js";
import { i as d } from "./vendor/react.js";
import { t as m } from "./useIsoLayoutEffect.js";
import { t as u } from "./useBaseUiId.js";
var L = /* @__PURE__ */ c(d());
function g(t, e, r, n = !0, i) {
  const [a, s] = L.useState(), f = u(i ? `${i}-label` : void 0), l = t ?? e ?? a;
  return m(() => {
    const o = t || e || !n ? void 0 : b(r.current, f);
    a !== o && s(o);
  }), l;
}
function b(t, e) {
  const r = p(t);
  if (r)
    return !r.id && e && (r.id = e), r.id || void 0;
}
function p(t) {
  if (!t) return;
  const e = t.parentElement;
  if (e && e.tagName === "LABEL") return e;
  const r = t.id;
  if (r) {
    const i = t.nextElementSibling;
    if (i && i.htmlFor === r) return i;
  }
  const n = t.labels;
  return n && n[0];
}
export {
  g as t
};

//# sourceMappingURL=useAriaLabelledBy.js.map