import { useForm } from 'react-hook-form' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import type { LessonType, ScheduleSlot } from '@/types/lesson' const DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] interface Props { lessonTypes: LessonType[] defaultValues?: Partial onSubmit: (data: Record) => void loading?: boolean } export function ScheduleSlotForm({ lessonTypes, defaultValues, onSubmit, loading }: Props) { const { register, handleSubmit, setValue, watch } = useForm({ defaultValues: { dayOfWeek: String(defaultValues?.dayOfWeek ?? 1), startTime: defaultValues?.startTime ?? '', lessonTypeId: defaultValues?.lessonTypeId ?? '', room: defaultValues?.room ?? '', maxStudents: String(defaultValues?.maxStudents ?? 1), rateWeekly: defaultValues?.rateWeekly ?? '', rateMonthly: defaultValues?.rateMonthly ?? '', rateQuarterly: defaultValues?.rateQuarterly ?? '', }, }) const dayOfWeek = watch('dayOfWeek') const lessonTypeId = watch('lessonTypeId') function handleFormSubmit(data: { dayOfWeek: string startTime: string lessonTypeId: string room: string maxStudents: string rateWeekly: string rateMonthly: string rateQuarterly: string }) { onSubmit({ dayOfWeek: Number(data.dayOfWeek), startTime: data.startTime, lessonTypeId: data.lessonTypeId, room: data.room || undefined, maxStudents: Number(data.maxStudents) || 1, rateWeekly: data.rateWeekly || undefined, rateMonthly: data.rateMonthly || undefined, rateQuarterly: data.rateQuarterly || undefined, }) } return (
) }