import type { RJSFSchema, UiSchema } from '@rjsf/utils';
import type { IChangeEvent, FormProps } from '@rjsf/core';

/**
 * JSON Schema Form props interface
 */
export interface JsonSchemaFormProps<T = any> extends Partial<FormProps<T>> {
  /** JSON Schema that defines the form structure */
  schema: RJSFSchema;

  /** UI Schema for customizing the form appearance */
  uiSchema?: UiSchema;

  /** Initial form data */
  formData?: T;

  /** Callback when form is submitted */
  onSubmit?: (data: IChangeEvent<T>) => void;

  /** Callback when form data changes */
  onChange?: (data: IChangeEvent<T>) => void;

  /** Callback when form has validation errors */
  onError?: (errors: any[]) => void;

  /** Whether to show error list at the top of form */
  showErrorList?: false | 'top' | 'bottom';

  /** Whether to live validate on change */
  liveValidate?: boolean;

  /** Whether the form is disabled */
  disabled?: boolean;

  /** Whether the form is read-only */
  readonly?: boolean;

  /** Custom CSS class name */
  className?: string;

  /** Whether to show submit button */
  showSubmitButton?: boolean;

  /** Submit button text */
  submitButtonText?: string;
}

/**
 * Field template props
 */
export interface FieldTemplateProps {
  id: string;
  label: string;
  required: boolean;
  description?: string;
  errors?: any;
  help?: string;
  displayLabel?: boolean;
  children: React.ReactNode;
  classNames?: string;
  rawErrors?: string[];
  schema: RJSFSchema;
}

/**
 * Widget props base interface
 */
export interface BaseWidgetProps {
  id: string;
  value: any;
  required: boolean;
  disabled: boolean;
  readonly: boolean;
  autofocus: boolean;
  onChange: (value: any) => void;
  onBlur: (id: string, value: any) => void;
  onFocus: (id: string, value: any) => void;
  options: any;
  schema: RJSFSchema;
  label: string;
  placeholder?: string;
  rawErrors?: string[];
}
