
export type FormFieldType =
  | "text"
  | "textarea"
  | "switch"
  | "number"
  | "checkbox"
  | "select"
  | "multiselect"
  | "password"
  | "date"
  | "datetime"
  | "dateinput"
  | "time"
  | "radio"
  | "file"
  | "color"
  | "slider"
  | "segmented"
  | "native-select"
  | "json"
  | "rating"
  | "autocomplete"
  | "richtext";

interface BaseFormField<T> {
  name: keyof T;
  label: string;
  description?: string;
  placeholder?: string;
  required?: boolean;
  disabled?: boolean;
  hidden?: boolean;
  className?: string;
  wrapperProps?: Record<string, unknown>;
  data?: any;
  clearable?: any;
}

interface RichTextFormField<T> extends BaseFormField<T> {
  type: "richtext";
  minHeight?: number;
  withTypography?: boolean;
  withLinks?: boolean;
  withImages?: boolean;
  withTextAlignment?: boolean;
  withColor?: boolean;
  withHighlight?: boolean;
}

type SpecificFormField<T> =
  | (BaseFormField<T> & { type: "text" })
  | (BaseFormField<T> & { type: "textarea" })
  | (BaseFormField<T> & { type: "switch" })
  | (BaseFormField<T> & { type: "number" })
  | (BaseFormField<T> & { type: "checkbox" })
  | (BaseFormField<T> & { type: "select" })
  | (BaseFormField<T> & { type: "multiselect" })
  | (BaseFormField<T> & { type: "password" })
  | (BaseFormField<T> & { type: "date" })
  | (BaseFormField<T> & { type: "datetime" })
  | (BaseFormField<T> & { type: "dateinput" })
  | (BaseFormField<T> & { type: "time" })
  | (BaseFormField<T> & { type: "radio" })
  | (BaseFormField<T> & { type: "file" })
  | (BaseFormField<T> & { type: "color" })
  | (BaseFormField<T> & { type: "slider" })
  | (BaseFormField<T> & { type: "segmented" })
  | (BaseFormField<T> & { type: "native-select" })
  | (BaseFormField<T> & { type: "json" })
  | (BaseFormField<T> & { type: "rating" })
  | (RichTextFormField<T> & { type: "richtext" })
  | (BaseFormField<T> & { type: "autocomplete" });

export type FormField<T> = SpecificFormField<T>;

// Updated GenericFormProps to work with our shadcn/Tailwind useGenericForm
export interface GenericFormProps<T> {
  form: {
    values: T;
    setValues: (values: Partial<T>) => void;
    errors: Record<string, string>;
    setError: (field: keyof T, message: string) => void;
    validate: () => boolean;
    reset: () => void;
    fields: FormField<T>[];
  };
  fields: FormField<T>[];
  onSubmit: (values: T) => Promise<void> | void;
  onCancel?: () => void;
  isLoading?: boolean;
  isSubmitting?: boolean;
  submitButtonText?: string;
  cancelButtonText?: string;
  successMessage?: string;
  errorMessage?: string;
  customButtons?: React.ReactNode;
  resetOnSuccess?: boolean;
}
