import { Signal, Value } from '@tempots/dom';
import { StandardSchemaV1 } from './schema/standard-schema-v1';
import { ControllerValidation, Controller, ObjectController } from './controller';
/**
 * Configuration options for creating a form with useForm.
 *
 * @template T - The form data type (must be an object)
 */
export interface UseFormOptions<T> {
    /** Optional schema for validation (supports Standard Schema v1, including Zod schemas). */
    schema?: StandardSchemaV1<T, T>;
    /** Initial form values (can be a static value or a reactive Signal). */
    initialValue?: Value<T>;
    /** Optional async submit handler that can return validation errors. */
    onSubmit?: (value: T) => Promise<ControllerValidation>;
    /** When to show validation errors: 'onSubmit' (default), 'eager' (immediately), or 'onTouched' (after blur). */
    validationMode?: 'onSubmit' | 'eager' | 'onTouched';
    /** Debounce delay in milliseconds for validation (useful for 'eager' mode). */
    validateDebounceMs?: number;
}
/**
 * Configuration options for creating a standalone controller with useController.
 *
 * @template T - The controller value type
 */
export interface UseControllerOptions<T> {
    /** Initial controller value (can be a static value or a reactive Signal). */
    initialValue: Value<T>;
    /** Optional callback invoked when the value changes. */
    onChange?: (value: T) => void;
    /** Optional validation function (sync or async). */
    validate?: (value: T) => Promise<ControllerValidation> | ControllerValidation;
    /** Equality function for dirty tracking (defaults to strictEqual). */
    equals?: (a: T, b: T) => boolean;
    /** When to show validation errors: 'onSubmit', 'eager', or 'onTouched' (default). */
    validationMode?: 'onSubmit' | 'eager' | 'onTouched';
    /** Debounce delay in milliseconds for validation. */
    validateDebounceMs?: number;
}
/**
 * Creates a standalone reactive controller for managing a single form field or value.
 * Provides reactive state management, validation, and touched/dirty tracking.
 *
 * @template T - The value type managed by the controller
 * @param options - Controller configuration options
 * @returns An object with the controller instance and a setStatus function for manual validation updates
 *
 * @example
 * ```typescript
 * import { useController, Control, TextInput } from '@tempots/beatui'
 * import { html } from '@tempots/dom'
 * import { z } from 'zod'
 * import { Validation } from '@tempots/std'
 *
 * const emailSchema = z.string().email()
 *
 * const { controller } = useController({
 *   initialValue: '',
 *   validate: async (value) => {
 *     const result = emailSchema.safeParse(value)
 *     return result.success
 *       ? Validation.valid
 *       : Validation.invalid({ message: result.error.errors[0].message })
 *   },
 *   validationMode: 'onTouched',
 * })
 *
 * const emailInput = Control(TextInput, {
 *   controller,
 *   label: 'Email',
 *   placeholder: 'you@example.com',
 * })
 * ```
 */
export declare function useController<T>({ initialValue, onChange, validate, equals, validationMode, validateDebounceMs, }: UseControllerOptions<T>): {
    controller: Controller<T>;
    setStatus: (result: ControllerValidation) => void;
};
/**
 * Connects common HTML attributes (disabled, name) from a controller to a DOM element.
 * This is a lower-level utility; most users should use Control/BaseControl instead.
 *
 * @template T - The controller value type
 * @param value - The controller to connect
 * @returns A Fragment with attribute bindings
 */
export declare function connectCommonAttributes<T>(value: Controller<T>): import("@tempots/dom").Renderable<import("@tempots/dom").DOMContext>;
/**
 * Connects a string controller to a text input element with value binding and event handlers.
 * This is a lower-level utility; most users should use Control/BaseControl instead.
 *
 * @param value - The string controller to connect
 * @param options - Configuration for when to trigger updates
 * @returns A Fragment with attribute and event bindings
 */
export declare function connectStringInput(value: Controller<string>, { triggerOn, }?: {
    triggerOn?: 'change' | 'input';
}): import("@tempots/dom").Renderable<import("@tempots/dom").DOMContext>;
/**
 * Connects a number controller to a number input element with value binding and event handlers.
 * This is a lower-level utility; most users should use Control/BaseControl instead.
 *
 * @param value - The number controller to connect
 * @param options - Configuration for when to trigger updates
 * @returns A Fragment with attribute and event bindings
 */
export declare function connectNumberInput(value: Controller<number>, { triggerOn, }?: {
    triggerOn?: 'change' | 'input';
}): import("@tempots/dom").Renderable<import("@tempots/dom").DOMContext>;
/**
 * Converts a Standard Schema v1 validation result into a ControllerValidation.
 * Used internally to integrate Standard Schema validators (including Zod) with the form system.
 *
 * @template Out - The validated output type
 * @param result - The Standard Schema validation result
 * @returns A ControllerValidation representing the result
 */
export declare function standardSchemaResultToValidation<Out>(result: StandardSchemaV1.Result<Out>): ControllerValidation;
/**
 * Wraps an async operation and converts any thrown errors into a ControllerValidation.
 * This is useful for form submission handlers that need to convert async operations
 * into the ControllerValidation format expected by the form system.
 *
 * @param task - The async operation to execute
 * @param errorMessage - Optional custom error message. If not provided, uses the error's message or a default message
 * @param errorPath - Optional path for the error. Defaults to ['root']
 * @returns A Promise that resolves to a ControllerValidation
 *
 * @example
 * ```typescript
 * const result = await taskToValidation(
 *   () => signUpUser(userData),
 *   'Sign up failed'
 * )
 * ```
 */
export declare function taskToValidation<T>({ task, errorMessage, errorPath, validation, }: {
    task: () => Promise<T>;
    errorMessage?: string;
    errorPath?: string[];
    validation?: (result: T) => ControllerValidation;
}): Promise<ControllerValidation>;
/**
 * The result returned by useForm, providing form state management and submission handling.
 *
 * @template T - The form data type
 */
export type UseFormResult<T extends object> = {
    /** The root ObjectController for accessing form fields via controller.field(). */
    controller: ObjectController<T>;
    /** Manually set the form's validation status (useful for server-side errors). */
    setStatus: (result: ControllerValidation) => void;
    /** Submit handler to attach to form onSubmit event. */
    submit: (e?: Event) => Promise<void>;
    /** Reactive signal indicating whether the form is currently submitting. */
    submitting: Signal<boolean>;
};
/**
 * Creates a complete form with validation, submission handling, and reactive state management.
 * Returns an ObjectController that provides field-level access and form-wide operations.
 *
 * @template T - The form data type (must be an object)
 * @param options - Form configuration options
 * @returns An object with controller, setStatus, submit handler, and submitting signal
 *
 * @example
 * ```typescript
 * import { useForm, Control, TextInput, Button } from '@tempots/beatui'
 * import { html, on } from '@tempots/dom'
 * import { z } from 'zod'
 *
 * const loginSchema = z.object({
 *   email: z.string().email('Invalid email address'),
 *   password: z.string().min(8, 'Password must be at least 8 characters'),
 * })
 *
 * const { controller, submit, submitting } = useForm({
 *   initialValue: { email: '', password: '' },
 *   schema: loginSchema,
 *   validationMode: 'onTouched',
 *   onSubmit: async (data) => {
 *     const response = await fetch('/api/login', {
 *       method: 'POST',
 *       body: JSON.stringify(data),
 *     })
 *     if (!response.ok) {
 *       return Validation.invalid({ message: 'Login failed' })
 *     }
 *     return Validation.valid
 *   },
 * })
 *
 * const loginForm = html.form(
 *   on.submit(submit),
 *   Control(TextInput, {
 *     controller: controller.field('email'),
 *     label: 'Email',
 *     type: 'email',
 *   }),
 *   Control(TextInput, {
 *     controller: controller.field('password'),
 *     label: 'Password',
 *     type: 'password',
 *   }),
 *   Button({ type: 'submit', disabled: submitting }, 'Sign In')
 * )
 * ```
 */
export declare function useForm<T extends object>({ initialValue, schema, onSubmit, validationMode, validateDebounceMs, }: UseFormOptions<T>): UseFormResult<T>;
