import { Synnax as Client } from '@synnaxlabs/client';
import { Destructor } from '@synnaxlabs/x';
import { z } from 'zod';
import { FetchOptions, Params } from './core/params';
import { Store } from './core/store';
import { Result } from './result';
import { UpdateArgs as BaseUpdateArgs } from './update';
import { Form } from '../form';
import { state } from '../state';
export interface FormUpdateArgs<UpdateParams extends Params, Schema extends z.ZodType<state.State>, ScopedStore extends Store = {}> extends Omit<BaseUpdateArgs<UpdateParams, z.infer<Schema>, ScopedStore>, "value" | "onChange">, Form.UseReturn<Schema> {
}
export interface FormRetrieveArgs<RetrieveParams extends Params, Schema extends z.ZodType<state.State>, ScopedStore extends Store = {}> extends Form.UseReturn<Schema> {
    client: Client;
    params: RetrieveParams;
    store: ScopedStore;
}
/**
 * Configuration arguments for creating a form query.
 *
 * @template FormParams The type of parameters for the form query
 * @template DataSchema The Zod schema type for form validation
 */
export interface CreateFormArgs<FormParams extends Params, DataSchema extends z.ZodType<state.State>, SubStore extends Store> {
    name: string;
    /** Zod schema for form validation */
    schema: DataSchema;
    /** Default values to use when creating new forms */
    initialValues: z.infer<DataSchema>;
    update: (args: FormUpdateArgs<FormParams, DataSchema, SubStore>) => Promise<void>;
    retrieve: (args: FormRetrieveArgs<FormParams, DataSchema, SubStore>) => Promise<void>;
    mountListeners?: (args: FormMountListenersArgs<SubStore, FormParams, DataSchema>) => Destructor | Destructor[];
}
/**
 * Return type for the form hook, providing form management utilities.
 *
 * @template DataSchema The Zod schema type for form validation
 */
export type UseFormReturn<DataSchema extends z.ZodType<state.State>> = Omit<Result<z.infer<DataSchema>>, "data"> & {
    /** Form management utilities for binding inputs and validation */
    form: Form.UseReturn<DataSchema>;
    /** Function to save the current form values */
    save: (opts?: FetchOptions) => void;
};
/**
 * Arguments passed to the afterSave callback.
 *
 * @template FormParams The type of parameters for the form query
 * @template Z The Zod schema type for form validation
 */
export interface BeforeSaveArgs<FormParams extends Params, Z extends z.ZodType<state.State>> extends Form.UseReturn<Z> {
    client: Client;
    /** The current form parameters */
    params: FormParams;
}
interface FormMountListenersArgs<ScopedStore extends Store, FormParams extends Params, Schema extends z.ZodType<state.State>> extends Form.UseReturn<Schema> {
    store: ScopedStore;
    client: Client;
    params: FormParams;
}
/**
 * Arguments passed to the afterSave callback.
 *
 * @template FormParams The type of parameters for the form query
 * @template Z The Zod schema type for form validation
 */
export interface AfterSaveArgs<FormParams extends Params, Z extends z.ZodType<state.State>> extends BeforeSaveArgs<FormParams, Z> {
}
/**
 * Arguments for using a form hook.
 *
 * @template FormParams The type of parameters for the form query
 * @template Z The Zod schema type for form validation
 */
export interface UseFormArgs<FormParams extends Params, Z extends z.ZodType<state.State>> extends Pick<Form.UseArgs<Z>, "sync" | "onHasTouched" | "mode"> {
    /** Initial values for the form fields */
    initialValues?: z.infer<Z>;
    /** Whether to automatically save form changes */
    autoSave?: boolean;
    /** Parameters for the form query */
    params: FormParams;
    /** Function to run before the save operation. If the function returns undefined,
     * the save will be cancelled. */
    beforeSave?: (args: BeforeSaveArgs<FormParams, Z>) => Promise<boolean>;
    /** Callback function called after successful save */
    afterSave?: (args: AfterSaveArgs<FormParams, Z>) => void;
    /** The scope to use for the form operation */
    scope?: string;
}
/**
 * Form hook function signature.
 *
 * @template FormParams The type of parameters for the form query
 * @template Z The Zod schema type for form validation
 */
export interface UseForm<FormParams extends Params, Z extends z.ZodType<state.State>> {
    (args: UseFormArgs<FormParams, Z>): UseFormReturn<Z>;
}
/**
 * Creates a form query hook that combines data fetching, form management, and real-time updates.
 *
 * This function creates a React hook that automatically handles:
 * - Data fetching with loading states
 * - Form validation using Zod schemas
 * - Automatic form saving and persistence
 * - Real-time synchronization with server state
 * - Error handling and user feedback
 *
 * @template FormParams The type of parameters for the form query
 * @template Schema The Zod schema type for form validation
 * @param config Configuration object with form schema, update function, and query settings
 * @returns A React hook for managing the form
 *
 * @example
 * ```typescript
 * const userSchema = z.object({
 *   name: z.string().min(1),
 *   email: z.string().email(),
 *   age: z.number().optional()
 * });
 *
 * const useUserForm = createForm({
 *   name: "user",
 *   schema: userSchema,
 *   initialValues: { name: "", email: "", age: undefined },
 *   retrieve: async ({ params, client }) => {
 *     return await client.users.retrieve(params.userId);
 *   },
 *   update: async ({ value, params, client }) => {
 *     await client.users.update(params.userId, value);
 *   }
 * });
 *
 * // Usage in component
 * const { form, save, variant } = useUserForm({
 *   params: { userId: 123 },
 *   afterSave: ({ form }) => {
 *     console.log("User saved:", form.value());
 *   }
 * });
 * ```
 */
export declare const createForm: <FormParams extends Params, Schema extends z.ZodType<state.State>, SubStore extends Store = {}>({ name, schema, retrieve, mountListeners, update, initialValues: baseInitialValues, }: CreateFormArgs<FormParams, Schema, SubStore>) => UseForm<FormParams, Schema>;
export {};
//# sourceMappingURL=form.d.ts.map