import { onCleanup, untrack } from "solid-js";
import { useBaseUiId } from "../base-ui-id.jsx";
import { useLabelableContext } from "./labelable-context.jsx";
/**
 * Register a labelable control's id with the surrounding
 * `<LabelableProvider>`. Labels rendered inside that provider can then read
 * `context.controlId()` to wire `htmlFor` / click-to-focus behavior.
 *
 * ### Lifecycle
 *
 * - On setup, resolves the id (override or generated) and registers it under
 *   a per-call `Symbol()` source key. Registration is synchronous so the
 *   context is populated before the first render of descendants reads it.
 * - On cleanup, unregisters the id. The provider falls back to its seeded
 *   default control id when no registrations remain (matching React).
 *
 * ### Relationship to React's `useLabelableId`
 *
 * React's version has an `implicit` branch that checks whether the control
 * is wrapped in a native `<label>` (and, if so, registers `null` to signal
 * implicit association). That DOM probe needs the host element. We have
 * deliberately **not** ported that branch here — the tier-2 components this
 * hook serves don't rely on implicit labelling. If/when a consumer needs it,
 * extend this hook to accept a `controlRef` + `implicit` flag and add a
 * post-mount registration step inside `onSettled`. For now keeping the
 * simpler shape honors the "no wrappers, clean cuts" policy.
 */
export function useLabelableId(params = {}) {
  const context = useLabelableContext();
  const idOverride = untrack(() => params.id);
  const id = useBaseUiId(idOverride);
  const source = Symbol("labelable-control");
  context.registerControlId(source, id);
  onCleanup(() => {
    context.registerControlId(source, undefined);
  });
  return {
    id
  };
}
//# sourceMappingURL=use-labelable-id.jsx.map
