'use client'; import React, { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; interface VideoFormData { title: string; description: string; videoUrl: string; videoType: 'YOUTUBE' | 'LOCAL'; isPublic: boolean; menuId?: string; } interface VideoFormProps { initialData?: VideoFormData; onSubmit?: (data: VideoFormData) => Promise; isEditing?: boolean; menus?: { id: string; title: string }[]; } export default function VideoForm({ initialData, onSubmit, isEditing = false, menus = [] }: VideoFormProps) { const router = useRouter(); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState(initialData || { title: '', description: '', videoUrl: '', videoType: 'YOUTUBE', isPublic: true, menuId: '', }); const handleChange = (e: React.ChangeEvent) => { const { name, value, type } = e.target; setFormData(prev => ({ ...prev, [name]: type === 'checkbox' ? (e.target as HTMLInputElement).checked : value, })); }; const handleSelectChange = (name: string, value: string) => { setFormData(prev => ({ ...prev, [name]: value === 'no-selection' ? '' : value, })); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { if (onSubmit) { await onSubmit(formData); } else { // Default submission logic if no prop provided console.log('Submitting video data:', formData); // Simulate API call await new Promise(resolve => setTimeout(resolve, 1000)); router.push('/dashboard/videos'); } } catch (error) { console.error('Error submitting form:', error); } finally { setLoading(false); } }; return (