import type { Dispatch, StateUpdater } from 'preact/hooks';
import type { NsTranslationKey, Translatable } from '../../../types';
import type { CapabilityName } from '../../core/models/api/capability';
import type { TrustedFieldsProvider } from '../../core/models/api/trusted-fields-provider';
import type { CountryCode } from '../../types/datasets/country-code';
import type { EntityProblems } from '../../types/errors/entity-problems';
import type { FormVerificationErrors } from '../../types/errors/form-verification-errors';
import type { FormModel } from '../../types/form';
import type { Mask } from '../../utils/masking/maskTypes';
import type { ValidationRuleResult, ValidatorMode, ValidatorRules } from '../../utils/validation/types';
export type FieldData<FieldSchema> = {
    [fieldData in keyof FieldSchema]: FieldSchema[fieldData];
};
export type FieldValid<FieldSchema> = {
    [fieldValid in keyof FieldSchema]: boolean;
};
type FieldErrors<FieldSchema> = {
    [fieldError in keyof FieldSchema]: Translatable | boolean;
};
type FieldLabels<FieldSchema> = {
    [fieldLabel in keyof FieldSchema]?: string;
};
export interface MaskSettings {
    mask?: Mask;
    transformOnType?: (val: string) => string;
}
export interface BaseFormFieldProps<FieldSchema> {
    data: FieldData<FieldSchema>;
    valid: FieldValid<FieldSchema>;
    errors: FieldErrors<FieldSchema>;
    labels: FieldLabels<FieldSchema>;
    readonly: boolean;
    shouldValidate?: boolean;
    optional?: boolean;
    mask?: MaskSettings;
    label?: string;
    guidanceText?: Partial<Record<keyof FieldSchema, string>>;
    className?: string;
    name?: string;
    requiredFields?: Partial<Array<keyof FieldSchema>>;
    handleChangeFor: (key: keyof FieldSchema, mode?: ValidatorMode) => (e: any) => void;
    setData?: (key: keyof FieldSchema, value: FieldValue<FieldSchema>) => void;
    setValid?: (key: keyof FieldSchema, value: boolean) => void;
    setErrors?: (key: keyof FieldSchema, value: ValidationRuleResult | null) => void;
    setFieldProblems?: (fieldProblems: Record<keyof FieldSchema, boolean>) => void;
    triggerValidation?: (schema?: Array<keyof FieldSchema>) => void;
    handleBlur?: (e: FocusEvent) => void;
}
export type FieldValue<FormSchema> = FormSchema[keyof FormSchema];
export interface FormState<FormSchema> {
    schema: Array<keyof FormSchema>;
    data: FormSchema;
    errors: Record<keyof FormSchema, ValidationRuleResult | null>;
    valid: Record<keyof FormSchema, boolean>;
    fieldProblems: Record<keyof FormSchema, boolean>;
    obscuredFields?: Array<keyof FormSchema>;
    optionalFields?: Array<keyof FormSchema>;
    trustedFields?: Array<string>;
    isValid?: boolean;
    dataStoreId?: string;
    local?: FormState<FormSchema> | Partial<FormState<FormSchema>>;
}
type InnerFormLabels<InnerFormSchema> = {
    [Field in keyof InnerFormSchema]: NsTranslationKey<'common'>;
};
export type OuterFormLabels<OuterFormSchema> = {
    [Form in keyof OuterFormSchema]: InnerFormLabels<OuterFormSchema[Form]>;
};
export interface Form<FormSchema> extends FormState<FormSchema> {
    setData: <Key extends keyof FormSchema>(key: Key, value: FormSchema[Key]) => void;
    setValid: (key: keyof FormSchema, value: boolean) => void;
    setErrors: (key: keyof FormSchema, value: ValidationRuleResult | null) => void;
    setFieldProblems: (fieldProblems: Record<keyof FormSchema, boolean>) => void;
    handleChangeFor: (key: keyof FormSchema, mode?: ValidatorMode) => (e: any) => void;
    triggerValidation: (schema?: Array<keyof FormSchema>) => void;
    mergeForm: (formValue: FormState<FormSchema>) => void;
    resetToDefaultData: () => void;
}
export interface BaseFormProps<FormSchema> {
    labels?: {
        [Field in keyof FormSchema]: NsTranslationKey<'common'>;
    };
    masks?: {
        [Field in keyof FormSchema]: MaskSettings;
    };
    data?: FormSchema;
    validators?: ValidatorRules<FormSchema>;
    ref?: any;
    heading?: string;
    name?: string;
    description?: string;
    readOnly?: boolean;
    shouldValidate?: boolean;
    trustedFieldsProvider?: TrustedFieldsProvider;
    onChange?(state: FormState<FormSchema>): void;
}
export interface BaseOuterFormProps<OuterFormSchema> extends BaseFormProps<OuterFormSchema> {
    problems?: EntityProblems;
    country?: CountryCode;
    activeForm?: FormModel;
    allFields?: {
        [InnerFormName in keyof OuterFormSchema]: Array<keyof OuterFormSchema[InnerFormName]>;
    };
    requiredFields?: {
        [InnerFormName in keyof OuterFormSchema]: Array<keyof OuterFormSchema[InnerFormName]>;
    };
    optionalFields?: {
        [InnerFormName in keyof OuterFormSchema]: Array<keyof OuterFormSchema[InnerFormName]>;
    };
    verifyFields?: {
        [InnerFormName in keyof OuterFormSchema]: Array<keyof OuterFormSchema[InnerFormName]>;
    };
    readOnlyFields?: {
        [InnerFormName in keyof OuterFormSchema]: Array<keyof OuterFormSchema[InnerFormName]>;
    };
    obscuredFields?: {
        [InnerFormName in keyof OuterFormSchema]: Array<keyof OuterFormSchema[InnerFormName]>;
    };
    trustedFields?: {
        [InnerFormName in keyof OuterFormSchema]: Array<keyof OuterFormSchema[InnerFormName]>;
    };
    setHideSidebar?: Dispatch<StateUpdater<boolean>>;
    setHideFooter?: Dispatch<StateUpdater<boolean>>;
    setSkipSubmit?: Dispatch<StateUpdater<boolean>>;
}
export interface BaseInnerFormProps<FormSchema> extends BaseFormProps<FormSchema> {
    formVerificationErrors?: FormVerificationErrors;
    allFields?: Array<keyof FormSchema>;
    requiredFields?: Array<keyof FormSchema>;
    obscuredFields?: Array<keyof FormSchema>;
    optionalFields?: Array<keyof FormSchema>;
    verifyFields?: Array<keyof FormSchema>;
    readOnlyFields?: Array<keyof FormSchema>;
    trustedFields?: Array<string>;
    fieldValidationErrors?: Partial<Record<keyof FormSchema, boolean>>;
    errors?: Partial<Record<keyof FormSchema, ValidationRuleResult | null>>;
    valid?: Partial<Record<keyof FormSchema, boolean>>;
    handleFieldChange?: (fieldName: keyof FormSchema, mode?: ValidatorMode) => (e: any) => void;
    id?: string;
    dataStoreId?: string;
    capabilities?: CapabilityName[];
    isTopLevelEntity?: boolean;
}
export {};
