import { createMemo } from "solid-js";
import { getCombinedFieldValidityData, useFieldRootContext } from "../../internals/field-context.jsx";

/**
 * Snapshot passed to `<Field.Validity>`'s function child. Mirrors React's
 * `FieldValidity.State` shape — the `state` slot (inside
 * `FieldValidityData`) is re-exposed as `validity` for API clarity.
 */

/**
 * Renders nothing by itself — passes the current validity snapshot to its
 * function child. Mirrors Base UI React's `<Field.Validity>`.
 *
 * Solid 2 note: the snapshot is recomputed inside a `createMemo` so the
 * function child re-evaluates only when the validity or external `invalid`
 * flag actually changes.
 */
export function FieldValidity(props) {
  const field = useFieldRootContext();
  const snapshot = createMemo(() => {
    const combined = getCombinedFieldValidityData(field.validityData(), field.invalid());
    return {
      validity: combined.state,
      errors: combined.errors,
      error: combined.error,
      value: combined.value,
      initialValue: combined.initialValue
    };
  });

  // Return a JSX expression that re-invokes the child as `snapshot()`
  // updates — Solid's compiler tracks this as a reactive dependency.
  return <>{props.children(snapshot())}</>;
}
//# sourceMappingURL=field-validity.jsx.map
