import { useFieldRootContext } from "../field-context.jsx";
import { mergePropsN } from "../merge-props-n.jsx";
import { ariaInvalid } from "../seed-aria-attr.jsx";
import { useFieldControlRegistration } from "../use-field-control-registration/use-field-control-registration.jsx";
/**
 * Compose `<Field.Root>`'s existing `useFieldValidation` machinery with
 * per-control registration for tier-2 widgets (checkbox, switch, radio, …).
 *
 * React parity: the React port splits this work across `useRegisterFieldControl`
 * and manual use of `validation` from the field-root context. Solid's
 * version collapses the two into a single hook so tier-2 components have a
 * single call site and don't need to pull `useFieldRootContext` themselves.
 *
 * Solid 2 notes:
 *
 * - Registration uses `useFieldControlRegistration` (P4), which installs
 *   its own `onCleanup` and `useValueChanged` bridge.
 * - `getValidationProps` / `getInputValidationProps` delegate to the parent
 *   field's pre-built props-factories — they already encode the correct
 *   `aria-invalid` semantics (literal `"true"` / `undefined` per RFC 07).
 * - When there's no `<Field.Root>` above, the hook still works: the noop
 *   field context returns pass-through props factories and a noop commit.
 */
export function useFieldControlValidation(params) {
  const field = useFieldRootContext();
  const {
    source
  } = useFieldControlRegistration({
    value: params.value,
    id: params.id,
    controlRef: params.controlRef,
    getValue: params.getValue,
    enabled: params.enabled
  });
  const getValidationProps = externalProps => field.validation.getValidationProps(externalProps);
  const getInputValidationProps = externalProps => field.validation.getInputValidationProps(externalProps);

  // Minimal aria-only projection. Re-reads the underlying field state on
  // every access so consumers splatting this into a reactive proxy (e.g.
  // `mergePropsN`) see the latest value. Outside a real `<Field.Root>` the
  // noop context has `present: false`; emit `undefined` so the key doesn't
  // appear on consumers that render standalone. WAI-ARIA 1.2 treats
  // `aria-invalid="false"` as equivalent to absent, so AT behavior is
  // unchanged.
  const getAriaInvalidProps = () => mergePropsN([ariaInvalid(() => {
    if (!field.present) return undefined;
    return field.state().valid === false;
  })]);
  return {
    getValidationProps,
    getInputValidationProps,
    getAriaInvalidProps,
    inputRef: field.validation.inputRef,
    commit: field.validation.commit,
    source
  };
}
//# sourceMappingURL=use-field-control-validation.jsx.map
