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