import { BaseField } from '../BaseField';
import { FormContext, Language } from './FormContext';
import { InterceptorBundle } from './InterceptorBundle';
import { Values } from './Values';
export declare type SubmitCallbackResponse = {
  values?: Values;
  errors?: Errors;
};
export declare type SubmitCallback = (values: Values, errors: Errors, context: FormContext) => SubmitCallbackResponse | void;
export interface ButtonProps {
  label: string;
  loading: boolean;
  type?: 'primary' | 'secondary' | 'danger';
  onClick: SubmitCallback;
}
export interface FormProps {
  error?: string;
  extraButtons?: ButtonProps[];
  fields: BaseField[];
  layout?: 'horizontal' | 'vertical';
  loading?: boolean;
  onChange?: SubmitCallback;
  onSubmit: SubmitCallback;
  passErrorsToSubmit?: boolean;
  showFieldOrder?: boolean;
  submitButtonLabel: string;
  showErrorsBelow?: boolean;
}
export declare type Errors = {
  [key: string]: string[];
};
export declare type Visibilities = {
  [key: string]: boolean;
};
export declare type StateInterceptors = {
  [key: string]: InterceptorBundle;
};
export interface FormState {
  context: FormContext;
  errors: Errors;
  interceptors: StateInterceptors;
  values: Values;
  visibilities: Visibilities;
}
export declare const defaultProps: Partial<FormProps>;
/**
 * Generates a context, default language is 'en'.
 * TODO the language and dictionary structure should be changed to something that makes more sense
 * @param language
 */
export declare function generateContext(language?: Language): FormContext;
/**
 * Generates the initial state from the props.
 * @param props
 * @param currentState
 */
export declare function generateState(fields: BaseField[], currentState?: FormState): FormState;
/**
 * Generates a new state when the value of a field changes.
 *
 * @param fields
 * @param state is the current state.
 * @param field that whose value is changed.
 * @param value is the new value of the given field.
 */
export declare function generateStateOnFieldChange(fields: BaseField[], state: FormState, field: BaseField, value: any): FormState;
/**
 * Generates a new state when the field loses the focus.
 *
 * @param state is the current state.
 * @param field that loses the focus.
 */
export declare function generateStateOnFieldBlur(state: FormState, field: BaseField): FormState;
/**
 * Executes the onSubmit interceptors on all fields and returns the field -> error map.
 * @param context
 * @param fields
 * @param interceptors
 * @param values
 * @param visibilities
 */
export declare function executeOnSubmitInterceptors(context: FormContext, fields: BaseField[], interceptors: StateInterceptors, values: Values, visibilities: Visibilities): Errors;
/**
 * Checks whether the errors map has any error and returns the first (field order) found error.
 * @param errors to check.
 * @return the error if exists, nothing otherwise.
 */
export declare function getFirstError(errors: {
  [key: string]: string[];
}): string | undefined;
/**
 * Merges the given id -> error maps into one map.
 * @param errors1
 * @param errors2
 */
export declare function mergeErrors(errors1: Errors, errors2: Errors): Errors;
/**
 * Executes the button callback and returns a new state with the values returned from the callback.
 * Returns nothing if the callback returns nothing.
 * @param fields
 * @param state
 * @param callback
 * @param passErrorsToCallback is used to call callback even though there are errors.
 */
export declare function handleButtonClick(fields: BaseField[], state: FormState, callback: SubmitCallback, passErrorsToCallback: boolean): FormState | undefined;
