import type { JSONSchema } from '../schema-context';
import { Prop } from '@tempots/dom';
import { ControllerValidation } from '../../form';
/**
 * Async validation rule configuration
 */
export interface AsyncValidationRule {
    /** Unique identifier for the rule */
    id: string;
    /** Field path to validate */
    field: string;
    /** Debounce delay in milliseconds (default: 300) */
    debounce?: number;
    /** Validation function */
    validate: (value: unknown, formData: unknown) => Promise<AsyncValidationResult>;
    /** Loading message to show during validation */
    loadingMessage?: string;
    /** Whether to validate on blur only (default: false) */
    validateOnBlurOnly?: boolean;
    /** Minimum value length to trigger validation */
    minLength?: number;
    /** Dependencies that should trigger revalidation */
    dependencies?: string[];
}
/**
 * Result of async validation
 */
export interface AsyncValidationResult {
    /** Whether validation passed */
    valid: boolean;
    /** Error message if validation failed */
    message?: string;
    /** Additional context for error reporting */
    context?: Record<string, unknown>;
}
/**
 * Async validation state
 */
export interface AsyncValidationState {
    /** Whether validation is currently running */
    isValidating: boolean;
    /** Current validation result */
    result: ControllerValidation;
    /** Last validated value */
    lastValidatedValue: unknown;
    /** Timestamp of last validation */
    lastValidatedAt: number;
}
/**
 * Built-in async validation rules
 */
export declare const BUILTIN_ASYNC_RULES: {
    /**
     * Check if username is available (example)
     */
    usernameAvailable: (field: string, checkAvailability: (username: string) => Promise<boolean>, options?: {
        minLength?: number;
        debounce?: number;
    }) => AsyncValidationRule;
    /**
     * Validate email format and check if it exists
     */
    emailExists: (field: string, checkExists: (email: string) => Promise<boolean>, options?: {
        debounce?: number;
    }) => AsyncValidationRule;
    /**
     * Custom API validation
     */
    apiValidation: (field: string, apiCall: (value: unknown, formData: unknown) => Promise<{
        valid: boolean;
        message?: string;
    }>, options?: {
        debounce?: number;
        minLength?: number;
        loadingMessage?: string;
    }) => AsyncValidationRule;
};
/**
 * Extract async validation rules from schema x:ui
 */
export declare function getAsyncValidationRules(schema: JSONSchema): AsyncValidationRule[];
/**
 * Async validator class that manages debouncing and state
 */
export declare class AsyncValidator {
    private timeouts;
    private validationStates;
    private abortControllers;
    /**
     * Create or get validation state signal for a field
     */
    getValidationState(fieldId: string): Prop<AsyncValidationState>;
    /**
     * Validate a field with debouncing
     */
    validateField(rule: AsyncValidationRule, value: unknown, formData: unknown, force?: boolean): Promise<void>;
    /**
     * Cancel all pending validations
     */
    cancelAll(): void;
    /**
     * Get current validation results for all fields
     */
    getAllValidationResults(): Record<string, ControllerValidation>;
    /**
     * Check if any validations are currently running
     */
    isValidating(): boolean;
    /**
     * Dispose of all resources
     */
    dispose(): void;
}
