'use client' import { useState } from 'react' import { useRouter } from '@/i18n/routing' import { generateItineraryAction } from '@/app/actions' import { Utensils, Waves, Mountain, Loader2 } from 'lucide-react' interface Option { value: string label: string } interface Translations { days: string style: string neighborhoods: string generate: string generating: string gastronomy: string relaxation: string adventure: string } interface FormProps { locale: string translations: Translations neighborhoods: Option[] } const STYLES = [ { value: 'gastronomy', icon: Utensils }, { value: 'relaxation', icon: Waves }, { value: 'adventure', icon: Mountain }, ] as const export default function PlannerForm({ locale, translations, neighborhoods }: FormProps) { const router = useRouter() const [days, setDays] = useState(3) const [style, setStyle] = useState('gastronomy') const [selectedNeighborhoods, setSelectedNeighborhoods] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState('') const styleLabels: Record = { gastronomy: translations.gastronomy, relaxation: translations.relaxation, adventure: translations.adventure, } const toggleNeighborhood = (slug: string) => { setSelectedNeighborhoods(prev => prev.includes(slug) ? prev.filter(s => s !== slug) : [...prev, slug] ) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError('') try { const res = await generateItineraryAction(days, style, selectedNeighborhoods, locale) if (res.success && res.id) { router.push(`/plan/${res.id}`) } else { setError(res.error || 'Bir hata oluştu. Lütfen tekrar deneyin.') setLoading(false) } } catch (err) { setError('Bir hata oluştu. Lütfen tekrar deneyin.') setLoading(false) } } return (
{error && (
{error}
)} {/* Days */}
{[1, 2, 3, 4, 5].map(n => ( ))}
{/* Style */}
{STYLES.map(({ value, icon: Icon }) => ( ))}
{/* Neighborhoods */} {neighborhoods.length > 0 && (
{neighborhoods.map(n => ( ))}
)}
) }