import type { DefaultValue, FieldName, FormValue } from './form';
export type SubmissionState = {
    validated: Record<string, boolean>;
};
export type SubmissionContext<Value = null, FormError = string[]> = {
    intent: Intent | null;
    payload: Record<string, unknown>;
    fields: Set<string>;
    value?: Value;
    error?: Record<string, FormError | null> | null;
    state?: SubmissionState;
};
export type Submission<Schema, FormError = string[], FormValue = Schema> = {
    status: 'success';
    payload: Record<string, unknown>;
    value: FormValue;
    reply(options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
} | {
    status: 'error' | undefined;
    payload: Record<string, unknown>;
    error: Record<string, FormError | null> | null;
    reply(options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
};
export type SubmissionResult<FormError = string[]> = {
    status?: 'error' | 'success';
    intent?: Intent;
    initialValue?: Record<string, unknown> | null;
    fields?: string[];
    error?: Record<string, FormError | null>;
    state?: SubmissionState;
};
export type ReplyOptions<FormError> = {
    resetForm?: boolean;
} | {
    formErrors?: FormError;
    fieldErrors?: Record<string, FormError>;
    hideFields?: string[];
};
/**
 * The name to be used when submitting a form control
 */
export declare const INTENT = "__intent__";
/**
 * The name to be used when submitting a state
 */
export declare const STATE = "__state__";
export declare function getSubmissionContext(body: FormData | URLSearchParams): SubmissionContext;
export declare function parse<FormValue, FormError>(payload: FormData | URLSearchParams, options: {
    resolve: (payload: Record<string, any>, intent: Intent | null) => {
        value?: FormValue;
        error?: Record<string, FormError | null> | null;
    };
}): Submission<FormValue, FormError>;
export declare function parse<FormValue, FormError>(payload: FormData | URLSearchParams, options: {
    resolve: (payload: Record<string, any>, intent: Intent | null) => Promise<{
        value?: FormValue;
        error?: Record<string, FormError | null> | null;
    }>;
}): Promise<Submission<FormValue, FormError>>;
export declare function parse<FormValue, FormError>(payload: FormData | URLSearchParams, options: {
    resolve: (payload: Record<string, any>, intent: Intent | null) => {
        value?: FormValue;
        error?: Record<string, FormError | null> | null;
    } | Promise<{
        value?: FormValue;
        error?: Record<string, FormError | null> | null;
    }>;
}): Submission<FormValue, FormError> | Promise<Submission<FormValue, FormError>>;
export declare function createSubmission<FormValue, FormError>(context: SubmissionContext<FormValue, FormError>): Submission<FormValue, FormError>;
export declare function replySubmission<FormError>(context: SubmissionContext<unknown, FormError>, options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
export type ValidateIntent<Schema = any> = {
    type: 'validate';
    payload: {
        name?: FieldName<Schema>;
    };
};
export type ResetIntent<Schema = any> = {
    type: 'reset';
    payload: {
        name?: FieldName<Schema>;
    };
};
export type UpdateIntent<Schema = unknown> = {
    type: 'update';
    payload: {
        name?: FieldName<Schema>;
        value?: NonNullable<DefaultValue<Schema>>;
        validated?: boolean;
    };
};
export type RemoveIntent<Schema extends Array<any> = any> = {
    type: 'remove';
    payload: {
        name: FieldName<Schema>;
        index: number;
    };
};
export type InsertIntent<Schema extends Array<any> = any> = {
    type: 'insert';
    payload: {
        name: FieldName<Schema>;
        defaultValue?: Schema extends Array<infer Item> ? DefaultValue<Item> : never;
        index?: number;
    };
};
export type ReorderIntent<Schema extends Array<any> = any> = {
    type: 'reorder';
    payload: {
        name: FieldName<Schema>;
        from: number;
        to: number;
    };
};
export type Intent<Schema = unknown> = ValidateIntent<Schema> | ResetIntent<Schema> | UpdateIntent<Schema> | ReorderIntent<Schema extends Array<any> ? Schema : any> | RemoveIntent<Schema extends Array<any> ? Schema : any> | InsertIntent<Schema extends Array<any> ? Schema : any>;
export declare function getIntent(serializedIntent: string | null | undefined): Intent | null;
export declare function serializeIntent<Schema>(intent: Intent<Schema>): string;
export declare function updateList(list: unknown, intent: InsertIntent | RemoveIntent | ReorderIntent): void;
export declare function setListValue(data: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent): void;
export declare function setState(state: Record<string, unknown>, name: string, valueFn: (value: unknown) => unknown): void;
export declare function setListState(state: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent, getDefaultValue?: () => string): void;
export declare function serialize<Schema>(defaultValue: DefaultValue<Schema>): FormValue<Schema>;
