import { createPortal } from 'react-dom' import { Ticket, FileText, ExternalLink, Footprints, ArrowRight, Pencil } from 'lucide-react' import Markdown from 'react-markdown' import remarkGfm from 'remark-gfm' import remarkBreaks from 'remark-breaks' import { markdownLinkComponents } from '../shared/markdownLink' import { useSettingsStore } from '../../store/settingsStore' import { useTripStore } from '../../store/tripStore' import { formatTime, splitReservationDateTime } from '../../utils/formatters' import { RES_ICONS, TRANSPORT_DETAIL_COLORS } from './DayPlanSidebar.constants' import type { Reservation } from '../../types' interface DayPlanSidebarTransportDetailModalProps { transportDetail: Reservation | null setTransportDetail: (v: Reservation | null) => void onNavigateToFiles?: () => void /** Opens the edit form for this reservation (shown as a footer action). */ onEdit?: (res: Reservation) => void t: (key: string, params?: Record) => string locale: string timeFormat: string } export function DayPlanSidebarTransportDetailModal({ transportDetail, setTransportDetail, onNavigateToFiles, onEdit, t, locale, timeFormat, }: DayPlanSidebarTransportDetailModalProps) { if (!transportDetail) return null return createPortal(
setTransportDetail(null)} onKeyDown={e => { if (e.target !== e.currentTarget) return if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setTransportDetail(null) } }}>
e.stopPropagation()}> {(() => { const res = transportDetail const TransportIcon = RES_ICONS[res.type] || Ticket const TRANSPORT_COLORS = TRANSPORT_DETAIL_COLORS const color = TRANSPORT_COLORS[res.type] || 'var(--text-muted)' const meta = typeof res.metadata === 'string' ? JSON.parse(res.metadata || '{}') : (res.metadata || {}) const detailFields = [] if (res.type === 'flight') { if (meta.airline) detailFields.push({ label: t('reservations.meta.airline'), value: meta.airline }) if (meta.flight_number) detailFields.push({ label: t('reservations.meta.flightNumber'), value: meta.flight_number }) if (meta.departure_airport) detailFields.push({ label: t('reservations.meta.from'), value: meta.departure_airport }) if (meta.arrival_airport) detailFields.push({ label: t('reservations.meta.to'), value: meta.arrival_airport }) if (meta.seat) detailFields.push({ label: t('reservations.meta.seat'), value: meta.seat }) } else if (res.type === 'train') { if (meta.train_number) detailFields.push({ label: t('reservations.meta.trainNumber'), value: meta.train_number }) if (meta.platform) detailFields.push({ label: t('reservations.meta.platform'), value: meta.platform }) if (meta.seat) detailFields.push({ label: t('reservations.meta.seat'), value: meta.seat }) } if (res.confirmation_number) detailFields.push({ label: t('reservations.confirmationCode'), value: res.confirmation_number, sensitive: true }) // A stopover booking can carry its own reference per segment (#1943); the // flat fields above only ever describe the first leg. Marked sensitive so // the blur setting covers them like the booking's own code. if (Array.isArray(meta.legs) && meta.legs.length > 1) { for (const leg of meta.legs) { if (!leg?.confirmation_number) continue const segment = [leg.from, leg.to].filter(Boolean).join(' → ') detailFields.push({ label: segment || t('reservations.confirmationCode'), value: leg.confirmation_number, sensitive: true }) } } if (res.location) detailFields.push({ label: t('reservations.locationAddress'), value: res.location }) return ( <> {/* Header */}
{res.title}
{(() => { const { date, time } = splitReservationDateTime(res.reservation_time) const { time: endTime } = splitReservationDateTime(res.reservation_end_time) const dateStr = date ? new Date(date + 'T00:00:00Z').toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'short', timeZone: 'UTC' }) : '' const timeStr = time ? formatTime(time, locale, timeFormat) : '' const endStr = endTime ? formatTime(endTime, locale, timeFormat) : '' const parts: string[] = [] if (dateStr) parts.push(dateStr) if (timeStr) parts.push(timeStr + (endStr ? ` – ${endStr}` : '')) return parts.join(', ') })()}
{res.status === 'confirmed' ? t('planner.resConfirmed') : t('planner.resPending')}
{/* Detail-Felder */} {detailFields.length > 0 && (
{detailFields.map((f, i) => { const shouldBlur = f.sensitive && useSettingsStore.getState().settings.blur_booking_codes const valueStyle = { fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontWeight: 500, wordBreak: 'break-word', filter: shouldBlur ? 'blur(5px)' : 'none', transition: 'filter 0.2s', cursor: shouldBlur ? 'pointer' : 'default', userSelect: shouldBlur ? 'none' : 'auto', } as const return (
{f.label}
{/* A hidden booking code is a reveal toggle, so it has to be a real button; a plain value stays inert text and out of the tab order. */} {shouldBlur ? ( ) : (
{f.value}
)}
) })}
)} {/* Public-transit itinerary (#1065) — legs from the transit search */} {meta.transit?.legs && Array.isArray(meta.transit.legs) && meta.transit.legs.length > 0 && ( <> {/* journey summary: duration · transfers · walking */}
{meta.transit.duration > 0 && ( {Math.floor(meta.transit.duration / 3600) > 0 ? `${Math.floor(meta.transit.duration / 3600)} h ${Math.round((meta.transit.duration % 3600) / 60)} min` : t('transit.min', { count: Math.round(meta.transit.duration / 60) })} )} · {meta.transit.transfers > 0 ? t('transit.transfers', { count: meta.transit.transfers }) : t('transit.direct')} {meta.transit.walk_seconds > 59 && ( <> · {t('transit.min', { count: Math.round(meta.transit.walk_seconds / 60) })} )}
{t('transit.itinerary')}
{meta.transit.legs.map((leg: { mode?: string; line?: string | null; line_color?: string | null; line_text_color?: string | null; headsign?: string | null; duration?: number; stops?: number; from?: { name?: string; time?: string | null }; to?: { name?: string; time?: string | null } }, i: number) => { const isWalk = leg.mode === 'WALK' const mins = leg.duration ? Math.round(leg.duration / 60) : null return (
{isWalk ? ( ) : ( {leg.line || leg.mode} )}
{isWalk ? {t('transit.walkTo', { name: leg.to?.name || '' })} : <> {leg.from?.name} {leg.to?.name} }
{[ leg.from?.time && !isWalk ? `${leg.from.time}${leg.to?.time ? ` – ${leg.to.time}` : ''}` : null, mins ? t('transit.min', { count: mins }) : null, !isWalk && leg.stops ? t('transit.stops', { count: leg.stops }) : null, !isWalk && leg.headsign ? `→ ${leg.headsign}` : null, ].filter(Boolean).join(' · ')}
) })}
)} {/* Notizen */} {res.notes && (
{t('reservations.notes')}
{res.notes}
)} {/* Dateien */} {(() => { const resFiles = (useTripStore.getState().files || []).filter(f => !f.deleted_at && ( f.reservation_id === res.id || (f.linked_reservation_ids && f.linked_reservation_ids.includes(res.id)) ) ) if (resFiles.length === 0) return null return (
{t('files.title')}
{resFiles.map(f => ( ))}
) })()} {/* Aktionen */}
{onEdit && ( )}
) })()}
, document.body ) }