// Booking a table (plan phase 3S, step S.6): how many people, which day, what time, and // (when the venue allows it) food ordered ahead to be ready on arrival. The days come with the // menu (ordering.reservations.days); the times of a day from the cloud, in venue time. import { useEffect, useMemo, useState } from 'react' import { Minus, Plus, Users } from 'lucide-react' import { fetchBookingSlots } from '../api' import { useT } from '../i18n' import { slotDays } from '../logic' export default function BookingPicker({ site, res, timeZone, booking, setBooking }) { const { t, lang } = useT() const [slots, setSlots] = useState(null) const set = patch => setBooking(b => ({ ...b, ...patch })) const day = booking.day ?? res.days[0] ?? null useEffect(() => { if (!day) return undefined let alive = true setSlots(null) fetchBookingSlots(site, day).then(d => alive && setSlots(d.slots)).catch(() => alive && setSlots([])) return () => { alive = false } }, [site, day]) const times = useMemo(() => slotDays(slots ?? [], timeZone)[0]?.times ?? [], [slots, timeZone]) const today = new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()) const dayLabel = iso => { const d = new Date(`${iso}T12:00:00Z`) const diff = Math.round((d - new Date(`${today}T12:00:00Z`)) / 86_400_000) if (diff === 0) return t('today') if (diff === 1) return t('tomorrow') return new Intl.DateTimeFormat(lang === 'el' ? 'el-GR' : 'en-GB', { weekday: 'short', day: 'numeric', month: 'short', timeZone: 'UTC' }).format(d) } const chip = on => `shrink-0 px-3.5 h-10 rounded-full text-sm font-semibold ${on ? 'bg-accent text-accent-fg' : 'bg-surface-2 text-ink-2'}` if (!res.days.length) return

{t('book.none')}

return (
{booking.party}
{res.days.map(d => ( ))}
{slots === null &&

{t('loading')}

} {slots !== null && times.length === 0 &&

{t('book.noTimes')}

} {times.map(s => ( ))}
{res.with_food && ( )}
) }