import type { FormState } from '../../hooks/useForm/types'; import type { Translatable } from '../../../types'; import type { CountryCode } from '../../types/datasets/country-code'; export type ValidatorMode = 'blur' | 'input'; export interface FieldData { key: keyof FormSchema; value: FormSchema[keyof FormSchema] | null; mode?: ValidatorMode; formName?: any; } export interface FieldContext { state: FormState; } export type Formatter = (value: ValueType | null, context?: FieldContext) => ValueType | null; export interface Format { formatter?: Formatter; format?: string; maxlength?: number; } export type FormatRules = Partial<{ [field in keyof FormSchema]: Format; }>; export type CountryFormatRules = Partial>>; export interface ValidationRuleResult { isValid: boolean; errorMessage?: Translatable; hasError: boolean; } export type ValidationRuleResults = Partial>; export interface ValidatorRule { validate: (value: ValueType | null, context?: FieldContext) => boolean; errorMessage?: Translatable | ((value: ValueType | null, context?: FieldContext) => Translatable | undefined); modes: readonly ValidatorMode[]; } interface AsyncValidatorRule { asyncValidate: (value: ValueType | null, context?: FieldContext) => Promise; errorMessage?: Translatable | ((value: ValueType | null, context?: FieldContext) => Translatable); modes: readonly ValidatorMode[]; } export type ValidatorRules = Partial<{ [field in keyof FormSchema]: ValidatorRule | ValidatorRule[]; }>; export type AsyncValidatorRules = Partial<{ [field in keyof FormSchema]: AsyncValidatorRule; }>; export {};