'use client' import { useState, useMemo, useCallback, useEffect } from 'react' import { useRouter } from 'next/navigation' import { useForm, UseFormReturn } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { z } from 'zod' import { motion, AnimatePresence } from 'motion/react' import { Waves, AlertCircle, Loader2, CheckCircle, ArrowLeft, ArrowRight, Clock, } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Textarea } from '@/components/ui/textarea' import { Label } from '@/components/ui/label' import { Checkbox } from '@/components/ui/checkbox' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { cn } from '@/lib/utils' import { StepWelcome, StepContact, StepProject, StepTeam, StepAdditional, StepReview, } from './apply-steps' import type { WizardConfig, WizardStepId, CustomField } from '@/types/wizard-config' import { getVisibleSteps, isFieldVisible, isFieldRequired, buildStepsArray, getCustomFieldsForStep, } from '@/lib/wizard-config' import { TeamMemberRole } from '@prisma/client' // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- interface ApplyWizardDynamicProps { mode: 'edition' | 'round' config: WizardConfig programName: string programYear: number programId?: string roundId?: string isOpen: boolean submissionDeadline?: Date | string | null onSubmit: (data: Record) => Promise isSubmitting: boolean } // --------------------------------------------------------------------------- // Animation variants // --------------------------------------------------------------------------- const variants = { enter: (dir: number) => ({ x: dir > 0 ? 50 : -50, opacity: 0 }), center: { x: 0, opacity: 1 }, exit: (dir: number) => ({ x: dir < 0 ? 50 : -50, opacity: 0 }), } // --------------------------------------------------------------------------- // Custom field renderer // --------------------------------------------------------------------------- function CustomFieldRenderer({ field, form, }: { field: CustomField form: UseFormReturn> }) { const { register, formState: { errors }, setValue, watch, } = form const value = watch(field.id) const error = errors[field.id] const labelEl = ( ) const helpEl = field.helpText ? (

{field.helpText}

) : null const errorEl = error ? (

{error.message as string}

) : null switch (field.type) { case 'text': return (
{labelEl} {helpEl} {errorEl}
) case 'textarea': return (
{labelEl} {helpEl}