import { useState } from 'react'; import { useAppStore } from '../store/useAppStore'; import { Reservation } from '../types'; const TAGS = ['Hochstuhl', 'Allergie', 'Fensterplatz', 'Geburtstag']; const GUEST_COUNTS = [1, 2, 3, 4, 5, 6, 7, 8, 10, 12]; function generateId() { return Math.random().toString(36).substring(2, 10); } function getTimeSlots() { const slots: string[] = []; for (let h = 10; h < 24; h++) { for (const m of [0, 15, 30, 45]) { slots.push(`${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`); } } return slots; } const TIME_SLOTS = getTimeSlots(); export default function BookingModal() { const { tables, prefillTableId, prefillTime, prefillDate, closeBookingModal, addReservation } = useAppStore(); const today = prefillDate ?? new Date().toISOString().slice(0, 10); const [guestCount, setGuestCount] = useState(2); const [date, setDate] = useState(today); const [startTime, setStartTime] = useState(prefillTime ?? '19:00'); const [endTime, setEndTime] = useState(() => { const start = prefillTime ?? '19:00'; const [h, m] = start.split(':').map(Number); const end = h + 1 + ':' + String(m).padStart(2, '0'); return end; }); const [firstName, setFirstName] = useState(''); const [lastName, setLastName] = useState(''); const [phone, setPhone] = useState(''); const [email, setEmail] = useState(''); const [tableId, setTableId] = useState(prefillTableId ?? tables[0]?.id ?? ''); const [notes, setNotes] = useState(''); const [selectedTags, setSelectedTags] = useState([]); const suggestedTables = tables.filter((t) => t.maxCapacity >= guestCount && t.status === 'FREE'); const toggleTag = (tag: string) => setSelectedTags((prev) => prev.includes(tag) ? prev.filter((t) => t !== tag) : [...prev, tag]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!firstName || !tableId) return; const reservation: Reservation = { id: generateId(), guest: { id: generateId(), firstName, lastName, phone: phone || undefined, email: email || undefined }, tableIds: [tableId], date, startTime, endTime, guestCount, status: 'CONFIRMED', notes, tags: selectedTags, createdAt: new Date().toISOString(), }; addReservation(reservation); closeBookingModal(); }; return (
{/* Header */}

Neue Reservierung

Schnellbuchung / Walk-In

{/* Person Count */}
{GUEST_COUNTS.map((n) => ( ))}
{/* Date & Time */}
setDate(e.target.value)} className="w-full bg-slate-800/60 border border-slate-700 rounded-xl px-3 py-2.5 text-sm text-slate-100 focus:outline-none focus:border-amber-500 transition" />
{/* Guest Info */}
setFirstName(e.target.value)} className="bg-slate-800/60 border border-slate-700 rounded-xl px-3 py-2.5 text-sm text-slate-100 focus:outline-none focus:border-amber-500 transition placeholder-slate-600" /> setLastName(e.target.value)} className="bg-slate-800/60 border border-slate-700 rounded-xl px-3 py-2.5 text-sm text-slate-100 focus:outline-none focus:border-amber-500 transition placeholder-slate-600" /> setPhone(e.target.value)} className="bg-slate-800/60 border border-slate-700 rounded-xl px-3 py-2.5 text-sm text-slate-100 focus:outline-none focus:border-amber-500 transition placeholder-slate-600" /> setEmail(e.target.value)} className="bg-slate-800/60 border border-slate-700 rounded-xl px-3 py-2.5 text-sm text-slate-100 focus:outline-none focus:border-amber-500 transition placeholder-slate-600" />
{/* Table Selection */}
{tables.map((t) => { const isSuggested = suggestedTables.some((s) => s.id === t.id); return ( ); })}
{/* Tags */}
{TAGS.map((tag) => ( ))}
{/* Notes */}