'use client'; import { useState, useEffect } from 'react'; import { FiCalendar, FiMapPin, FiUser, FiMail, FiPhone, FiCamera, FiCheck, FiAlertCircle } from 'react-icons/fi'; interface Location { id: string; name: string; slug: string; city: string; } interface PriceConfig { model: string; basePrice: number; pricePerKm: number; includedKm: number; } const photoboxModels = [ { value: 'VINTAGE_SMILE', label: 'Vintage Smile', description: 'Klassische Vintage-Box mit Sofortdruck' }, { value: 'VINTAGE_PHOTOS', label: 'Vintage Photos', description: 'Vintage-Box mit erweiterten Funktionen' }, { value: 'NOSTALGIE', label: 'Nostalgie', description: 'Nostalgische Fotobox im Retro-Design' }, { value: 'MAGIC_MIRROR', label: 'Magic Mirror', description: 'Interaktiver Fotospiegel' }, ]; export default function BookingFormPage() { const [step, setStep] = useState(1); const [locations, setLocations] = useState([]); const [priceConfigs, setPriceConfigs] = useState([]); const [availability, setAvailability] = useState(null); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const [error, setError] = useState(''); const [formData, setFormData] = useState({ locationSlug: '', model: '', customerName: '', customerEmail: '', customerPhone: '', customerAddress: '', customerCity: '', customerZip: '', invoiceType: 'PRIVATE', companyName: '', eventDate: '', eventAddress: '', eventCity: '', eventZip: '', eventLocation: '', setupTimeStart: '', setupTimeLatest: '', dismantleTimeEarliest: '', dismantleTimeLatest: '', notes: '', }); useEffect(() => { fetch('/api/locations') .then(res => res.json()) .then(data => setLocations(data.locations || [])); }, []); useEffect(() => { if (formData.locationSlug) { fetch(`/api/prices?location=${formData.locationSlug}`) .then(res => res.json()) .then(data => setPriceConfigs(data.prices || [])); } }, [formData.locationSlug]); useEffect(() => { if (formData.locationSlug && formData.model && formData.eventDate) { checkAvailability(); } }, [formData.locationSlug, formData.model, formData.eventDate]); const checkAvailability = async () => { try { const res = await fetch( `/api/availability?location=${formData.locationSlug}&model=${formData.model}&date=${formData.eventDate}` ); const data = await res.json(); setAvailability(data); } catch (err) { console.error('Availability check failed:', err); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const res = await fetch('/api/bookings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData), }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || 'Buchung fehlgeschlagen'); } setSuccess(true); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; const getPrice = () => { const config = priceConfigs.find(p => p.model === formData.model); return config ? config.basePrice : 0; }; if (success) { return (

Anfrage erfolgreich!

Vielen Dank für Ihre Buchungsanfrage. Wir melden uns in Kürze bei Ihnen mit allen Details.

Weitere Buchung
); } return (

Fotobox buchen

Save the Moment - Ihr Event, unvergesslich

{[1, 2, 3].map((s) => (
= s ? 'bg-red-600 text-white' : 'bg-gray-200 text-gray-500' }`} > {s}
{s < 3 &&
s ? 'bg-red-600' : 'bg-gray-200'}`} />}
))}
{step === 1 && (

Standort & Fotobox wählen

{photoboxModels.map((model) => { const price = priceConfigs.find(p => p.model === model.value); return ( ); })}
setFormData({ ...formData, eventDate: e.target.value })} required min={new Date().toISOString().split('T')[0]} className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" /> {availability && (
{availability.message}
)}
)} {step === 2 && (

Ihre Kontaktdaten

{formData.invoiceType === 'BUSINESS' && (
setFormData({ ...formData, companyName: e.target.value })} className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
)}
setFormData({ ...formData, customerName: e.target.value })} required className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, customerEmail: e.target.value })} required className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, customerPhone: e.target.value })} required className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, customerAddress: e.target.value })} className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, customerZip: e.target.value })} className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, customerCity: e.target.value })} className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
)} {step === 3 && (

Event-Details

setFormData({ ...formData, eventAddress: e.target.value })} required placeholder="Straße und Hausnummer" className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, eventZip: e.target.value })} required className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, eventCity: e.target.value })} required className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, eventLocation: e.target.value })} placeholder="z.B. Hotel Maritim, Villa Rosengarten" className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, setupTimeStart: e.target.value })} required className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, setupTimeLatest: e.target.value })} required className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, dismantleTimeEarliest: e.target.value })} className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, dismantleTimeLatest: e.target.value })} className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />