/**
 * Shared constants and pure helpers for `<Field.Root>` / `<Form>` validity.
 *
 * Mirrors Base UI React's
 * `packages/react/src/internals/field-constants/constants.ts` and
 * `packages/react/src/field/utils/getCombinedFieldValidityData.ts`, kept in
 * one module so the solid port can import everything from a single path.
 */

/**
 * Validity snapshot for a field. Mirrors the HTML `ValidityState` surface,
 * plus Base UI's `valid` overall flag (tri-state: `true`/`false`/`null`
 * meaning "not yet validated").
 */

export const DEFAULT_VALIDITY_STATE = {
  badInput: false,
  customError: false,
  patternMismatch: false,
  rangeOverflow: false,
  rangeUnderflow: false,
  stepMismatch: false,
  tooLong: false,
  tooShort: false,
  typeMismatch: false,
  valid: null,
  valueMissing: false
};

/**
 * Entire payload we keep per-field: the last-seen value, the initial value,
 * the computed validity state and the flat error list (both the canonical
 * first error and the full array of errors emitted by `validate`).
 */

export const DEFAULT_FIELD_STATE_ATTRIBUTES = {
  valid: null,
  touched: false,
  dirty: false,
  filled: false,
  focused: false
};
export const DEFAULT_FIELD_ROOT_STATE = {
  disabled: false,
  ...DEFAULT_FIELD_STATE_ATTRIBUTES
};
/**
 * `data-*` projection for the validity portion of the field state. The
 * `valid` slot is tri-state (`true`/`false`/`null`): the `null` case means
 * "not yet validated" and MUST not emit any attribute, so nothing can lean
 * on `data-valid=""` until a commit has landed.
 */
export const fieldValidityMapping = {
  valid(value) {
    if (value === null) {
      return null;
    }
    if (value) {
      return {
        "data-valid": ""
      };
    }
    return {
      "data-invalid": ""
    };
  }
};

/**
 * Merge a field's internally-tracked validity with the externally-supplied
 * `invalid` prop. A field is considered valid only if both agree — external
 * `invalid=true` forces an invalid state regardless of the client-side check.
 */
export function getCombinedFieldValidityData(validityData, invalid) {
  return {
    ...validityData,
    state: {
      ...validityData.state,
      valid: !invalid && validityData.state.valid
    }
  };
}

/**
 * Pure factory for a blank `FieldValidityData`. Mirrors the constant object
 * React uses as the context default, but fresh each call so mutable code
 * paths can't alias the shared instance.
 */
export function createDefaultValidityData(initialValue = null) {
  return {
    state: {
      ...DEFAULT_VALIDITY_STATE
    },
    errors: [],
    error: "",
    value: "",
    initialValue
  };
}
//# sourceMappingURL=field-constants.jsx.map
