import type { SvelteComponentTyped } from "svelte/internal";
import type { Readable } from "svelte/store";

import type { FormControl, RuleExpression } from "../types";

export interface FieldProps<T = any> {
  name: string;
  defaultValue?: T;
  bail?: boolean;
  validateOnBlur?: boolean;
  validateOnMount?: boolean;
  control?: Readable<FormControl<T>> | null;
  rules?: RuleExpression;
}

export interface FieldEvents {}

export interface FieldSlots<T = any> {
  default: {
    pending: false;
    valid: false;
    dirty: false;
    touched: false;
    errors: any[];
    value: T;
    field: any;
    onChange: (e: any) => void;
    onFocus: () => void;
    onBlur: () => void;
  };
}

/**
 *
 * ```svelte
 * <Field name="email" rules="required|email" let:field>
 *   <input type="text" use:field />
 * </Field>
 * ```
 */
export declare class Field extends SvelteComponentTyped<
  FieldProps,
  FieldEvents,
  FieldSlots
> {}

export default Field;
