/// <reference types="@mini-types/global" />
import { InternalRuleItem, Value, Values, RuleItem, ValidateMessages } from 'async-validator';
import { IMixin4Legacy } from '@mini-types/alipay';
export { Value, Values };
export type Validator = (rule: Omit<InternalRuleItem, 'validator' | 'asyncValidator'>, value: Value) => void | Promise<void>;
export type ValidatorRender = (form: Form) => {
    validator: Validator;
};
export type FormRuleItem = Omit<RuleItem, 'asyncValidator'> | ValidatorRender;
export type Rule = FormRuleItem | FormRuleItem[];
export type Rules = Record<string, Rule>;
export type FormConfig = {
    rules?: Rules;
    initialValues?: Values;
    validateMessages?: ValidateMessages;
};
export type ValidateStatus = 'default' | 'success' | 'error' | 'validating';
export interface ValidatorStatus {
    status: ValidateStatus;
    errors: string[];
}
export interface FromItemRef {
    setFormData: (values: Values) => void;
    getFormData: () => Values;
    getProps: () => Record<string, Value>;
    on: (callback: (trigger: EventTrigger, value?: Value) => void) => void;
}
export type ValidateTrigger = 'onChange' | 'onBlur' | 'onFocus';
export type EventTrigger = ValidateTrigger | 'didUnmount' | 'deriveDataFromProps';
export declare class Form {
    /**
     * 表单初始值
     */
    private initialValues;
    /**
     * 原始规则，用户传入的跟之前的规则区别在于validator
     */
    private rules;
    /**
     * 表单ref组件对象
     */
    private fields;
    /**
     * 验证提示模板
     */
    private validateMessages;
    /**
     * 表单字段 change侦听
     */
    private changeListeners;
    /**
     * 依赖表
     */
    private dependenciesMap;
    /**
     * Form构建
     * @param formConfig 表单配置项
     */
    constructor(formConfig?: FormConfig);
    /**
     * 用户传入的rules转换成async-validator rules
     * @param rules 校验规则
     */
    private transformRules;
    /**
     * 遍历表单field对象
     * @param callback
     */
    private eachField;
    /**
     * 设置 rules
     * @param rules
     */
    private setRules;
    /**
     * 添加表单对象
     * @param ref 表单ref对象
     */
    addItem(ref: FromItemRef, customName?: string): void;
    /**
     * 设置表单值
     * @param name 表单名称
     * @param value 表单初始值
     */
    setFieldValue(name: string, value: Value): void;
    /**
     * 设置表单值
     * @param name 表单名称
     * @param value 表单初始值
     */
    setFieldsValue(values: Values): void;
    /**
     * 设置 initialValues，这个操作不会对页面进行修改，要是需要重置表单可跟上 reset 方法；
     * 这样是对于表单已经在编辑，但是需要重新initialValues的场景
     *
     * eg:
     *    this.setInitialValues(initialValues);
     *    this.reset();
     *
     * @param initialValues
     */
    setInitialValues(initialValues: Values): void;
    /**
     * 获取对应字段名的值
     * @param name
     * @returns
     */
    getFieldValue(name: string): any;
    /**
     * 获取一组字段名对应的值
     * @param nameList
     * @returns
     */
    getFieldsValue(nameList?: string[]): Values;
    /**
     * 获取对应字段名的校验器状态
     * @param name
     * @returns
     */
    getFieldValidatorStatus(name: string): ValidatorStatus;
    /**
     * 获取一组字段名的校验器状态
     * @param nameList
     * @returns
     */
    getFieldsValidatorStatus(nameList?: string[]): Record<string, ValidatorStatus>;
    /**
     * 设置对应字段名的校验器状态
     * @param name 表单名称
     * @param validatorStatus 校验状态
     * @returns
     */
    setFieldValidatorStatus(name: string, validatorStatus: ValidatorStatus): void;
    /**
     * 设置一组字段名的校验器状态
     * @param fieldsValidatorStatus 表单校验状态
     * @returns
     */
    setFieldsValidatorStatus(fieldsValidatorStatus: Record<string, ValidatorStatus>): void;
    /**
     * 检查对应字段是否被用户操作过
     * @param name 字段名称
     * @returns
     */
    isFieldTouched(name: string): boolean;
    /**
     * 指定表单字段值更新时触发回调方法
     * @param name 表单字段名称
     * @param callback 回调方法
     */
    onValueChange(name: string, callback: (value: Value, allValues: Values) => void): void;
    /**
     * 表单字段值更新时触发回调方法
     * @param name 表单字段名称
     * @param callback 回调方法
     */
    onValuesChange(callback: (changedValues: Values, allValues: Values) => void): void;
    /**
     * 表单提交
     */
    submit(): Promise<Values>;
    /**
     * 表单重置
     */
    reset(): void;
}
export declare function createForm({ methods }?: {
    methods?: {};
}): IMixin4Legacy<{
    formData: {
        value: Value;
    } & ValidatorStatus;
}, Record<string, any>, {
    emit(trigger: EventTrigger, value?: Value): void;
    setFormData(values: Values): void;
    getFormData(): {
        value: Value;
    } & ValidatorStatus;
    on(callback: (trigger: EventTrigger, value?: Value) => void): void;
    getProps: Record<string, any>;
}, MiniProgram.UnknownRecord, MiniProgram.UnknownRecord>;
