import React, { useState, useMemo } from 'react' import ReactDOM from 'react-dom' import { useTripStore } from '../../store/tripStore' import { useSettingsStore } from '../../store/settingsStore' import { useToast } from '../shared/Toast' import { useTranslation } from '../../i18n' import { CustomDateTimePicker } from '../shared/CustomDateTimePicker' import CustomSelect from '../shared/CustomSelect' import { Plane, Hotel, Utensils, Train, Car, Ship, Ticket, FileText, MapPin, Calendar, Hash, CheckCircle2, Circle, Pencil, Trash2, Plus, ChevronDown, ChevronRight, MapPinned, X, Users, ExternalLink, BookMarked, Lightbulb, } from 'lucide-react' const TYPE_OPTIONS = [ { value: 'flight', labelKey: 'reservations.type.flight', Icon: Plane }, { value: 'hotel', labelKey: 'reservations.type.hotel', Icon: Hotel }, { value: 'restaurant', labelKey: 'reservations.type.restaurant', Icon: Utensils }, { value: 'train', labelKey: 'reservations.type.train', Icon: Train }, { value: 'car', labelKey: 'reservations.type.car', Icon: Car }, { value: 'cruise', labelKey: 'reservations.type.cruise', Icon: Ship }, { value: 'event', labelKey: 'reservations.type.event', Icon: Ticket }, { value: 'tour', labelKey: 'reservations.type.tour', Icon: Users }, { value: 'other', labelKey: 'reservations.type.other', Icon: FileText }, ] function typeIcon(type) { return (TYPE_OPTIONS.find(t => t.value === type) || TYPE_OPTIONS[TYPE_OPTIONS.length - 1]).Icon } function typeLabelKey(type) { return (TYPE_OPTIONS.find(t => t.value === type) || TYPE_OPTIONS[TYPE_OPTIONS.length - 1]).labelKey } function formatDateTimeWithLocale(str, locale, timeFormat) { if (!str) return null const d = new Date(str) if (isNaN(d)) return str const datePart = d.toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'long' }) const h = d.getHours(), m = d.getMinutes() let timePart if (timeFormat === '12h') { const period = h >= 12 ? 'PM' : 'AM' const h12 = h === 0 ? 12 : h > 12 ? h - 12 : h timePart = `${h12}:${String(m).padStart(2, '0')} ${period}` } else { timePart = `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}` if (locale?.startsWith('de')) timePart += ' Uhr' } return `${datePart} · ${timePart}` } const inputStyle = { width: '100%', border: '1px solid var(--border-primary)', borderRadius: 10, padding: '8px 12px', fontSize: 13.5, fontFamily: 'inherit', outline: 'none', boxSizing: 'border-box', color: 'var(--text-primary)', background: 'var(--bg-card)', } const labelStyle = { display: 'block', fontSize: 12, fontWeight: 600, color: 'var(--text-secondary)', marginBottom: 5 } function PlaceReservationEditModal({ item, tripId, onClose }) { const { updatePlace } = useTripStore() const toast = useToast() const { t } = useTranslation() const [form, setForm] = useState({ reservation_status: item.status === 'confirmed' ? 'confirmed' : 'pending', reservation_datetime: item.reservation_time ? item.reservation_time.slice(0, 16) : '', place_time: item.place_time || '', reservation_notes: item.notes || '', }) const [saving, setSaving] = useState(false) const set = (f, v) => setForm(p => ({ ...p, [f]: v })) const handleSave = async () => { setSaving(true) try { await updatePlace(tripId, item.placeId, { reservation_status: form.reservation_status, reservation_datetime: form.reservation_datetime || null, place_time: form.place_time || null, reservation_notes: form.reservation_notes || null, }) toast.success(t('reservations.toast.updated')) onClose() } catch { toast.error(t('reservations.toast.saveError')) } finally { setSaving(false) } } return ReactDOM.createPortal(
e.stopPropagation()}>

{t('reservations.editTitle')}

{item.title}

set('reservation_status', v)} options={[ { value: 'pending', label: t('reservations.pending') }, { value: 'confirmed', label: t('reservations.confirmed') }, ]} />
set('reservation_datetime', v)} />