import { FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/src/components/ui/form"; import { RadioGroup, RadioGroupItem } from "@/src/components/ui/radio-group"; import { Textarea } from "@/src/components/ui/textarea"; import { Input } from "@/src/components/ui/input"; import { Label } from "@/src/components/ui/label"; import type { Control, Path } from "react-hook-form"; import type { SurveyQuestion, SurveyFormData } from "../lib/surveyTypes"; const AUTO_ADVANCE_DELAY = 300; interface SurveyStepProps { question: SurveyQuestion; control: Control; onAutoAdvance?: (selectedValue?: string) => void; isLast?: boolean; } export function SurveyStep({ question, control, onAutoAdvance, isLast = false, }: SurveyStepProps) { const fieldName = question.id as keyof SurveyFormData; const handleAutoAdvanceWithTimeout = (selectedValue?: string) => { if (onAutoAdvance) { // For signupReason question, ignore isLast and let the hook decide // For other questions, respect the isLast prop const shouldAutoAdvance = question.id === "signupReason" || !isLast; if (shouldAutoAdvance) { setTimeout(() => { onAutoAdvance(selectedValue); }, AUTO_ADVANCE_DELAY); } } }; if (question.type === "radio") { return ( } render={({ field }) => ( {question.question} { field.onChange(value); setTimeout(() => { handleAutoAdvanceWithTimeout(value); }, 0); }} value={field.value as string} className="grid gap-3" > {question.options.map((option) => ( ))} )} /> ); } if (question.type === "text") { return ( } render={({ field }) => ( {question.question} {question.id === "referralSource" ? ( ) : (