import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react' import ReactDOM from 'react-dom' import { useParams, useNavigate } from 'react-router-dom' import { useTripStore } from '../store/tripStore' import { useCanDo } from '../store/permissionsStore' import { useSettingsStore } from '../store/settingsStore' import { MapView } from '../components/Map/MapView' import { getCached, fetchPhoto } from '../services/photoService' import DayPlanSidebar from '../components/Planner/DayPlanSidebar' import PlacesSidebar from '../components/Planner/PlacesSidebar' import PlaceInspector from '../components/Planner/PlaceInspector' import DayDetailPanel from '../components/Planner/DayDetailPanel' import PlaceFormModal from '../components/Planner/PlaceFormModal' import TripFormModal from '../components/Trips/TripFormModal' import TripMembersModal from '../components/Trips/TripMembersModal' import { ReservationModal } from '../components/Planner/ReservationModal' // MemoriesPanel moved to Journey addon import ReservationsPanel from '../components/Planner/ReservationsPanel' import PackingListPanel from '../components/Packing/PackingListPanel' import TodoListPanel from '../components/Todo/TodoListPanel' import FileManager from '../components/Files/FileManager' import BudgetPanel from '../components/Budget/BudgetPanel' import CollabPanel from '../components/Collab/CollabPanel' import Navbar from '../components/Layout/Navbar' import { useToast } from '../components/shared/Toast' import { Map, X, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, Ticket, PackageCheck, Wallet, FolderOpen, Users } from 'lucide-react' import { useTranslation } from '../i18n' import { addonsApi, accommodationsApi, authApi, tripsApi, assignmentsApi, mapsApi } from '../api/client' import { accommodationRepo } from '../repo/accommodationRepo' import { offlineDb } from '../db/offlineDb' import { useAuthStore } from '../store/authStore' import ConfirmDialog from '../components/shared/ConfirmDialog' import { useResizablePanels } from '../hooks/useResizablePanels' import { useTripWebSocket } from '../hooks/useTripWebSocket' import { useRouteCalculation } from '../hooks/useRouteCalculation' import { usePlaceSelection } from '../hooks/usePlaceSelection' import { usePlannerHistory } from '../hooks/usePlannerHistory' import type { Accommodation, TripMember, Day, Place, Reservation, PackingItem, TodoItem } from '../types' import { ListTodo } from 'lucide-react' function ListsContainer({ tripId, packingItems, todoItems }: { tripId: number; packingItems: PackingItem[]; todoItems: TodoItem[] }) { const [subTab, setSubTab] = useState<'packing' | 'todo'>(() => { return (sessionStorage.getItem(`trip-lists-subtab-${tripId}`) as 'packing' | 'todo') || 'packing' }) const setSubTabPersist = (tab: 'packing' | 'todo') => { setSubTab(tab); sessionStorage.setItem(`trip-lists-subtab-${tripId}`, tab) } const { t } = useTranslation() return (
{([ { id: 'packing' as const, label: t('todo.subtab.packing'), icon: PackageCheck }, { id: 'todo' as const, label: t('todo.subtab.todo'), icon: ListTodo }, ]).map(tab => ( ))}
{subTab === 'packing' && } {subTab === 'todo' && }
) } export default function TripPlannerPage(): React.ReactElement | null { const { id: tripId } = useParams<{ id: string }>() const navigate = useNavigate() const toast = useToast() const { t, language } = useTranslation() const { settings } = useSettingsStore() const placesPhotosEnabled = useAuthStore(s => s.placesPhotosEnabled) const trip = useTripStore(s => s.trip) const days = useTripStore(s => s.days) const places = useTripStore(s => s.places) const assignments = useTripStore(s => s.assignments) const packingItems = useTripStore(s => s.packingItems) const todoItems = useTripStore(s => s.todoItems) const categories = useTripStore(s => s.categories) const reservations = useTripStore(s => s.reservations) const budgetItems = useTripStore(s => s.budgetItems) const files = useTripStore(s => s.files) const selectedDayId = useTripStore(s => s.selectedDayId) const isLoading = useTripStore(s => s.isLoading) // Actions — stable references, don't cause re-renders const tripActions = useRef(useTripStore.getState()).current const can = useCanDo() const canUploadFiles = can('file_upload', trip) const { pushUndo, undo, canUndo, lastActionLabel } = usePlannerHistory() const handleUndo = useCallback(async () => { const label = lastActionLabel await undo() toast.info(t('undo.done', { action: label ?? '' })) }, [undo, lastActionLabel, toast]) const [enabledAddons, setEnabledAddons] = useState>({ packing: true, budget: true, documents: true, collab: false }) const [collabFeatures, setCollabFeatures] = useState<{ chat: boolean; notes: boolean; polls: boolean; whatsnext: boolean }>({ chat: true, notes: true, polls: true, whatsnext: true }) const [tripAccommodations, setTripAccommodations] = useState([]) const [allowedFileTypes, setAllowedFileTypes] = useState(null) const [tripMembers, setTripMembers] = useState([]) const loadAccommodations = useCallback(() => { if (tripId) { accommodationRepo.list(tripId).then(d => setTripAccommodations(d.accommodations || [])).catch(() => {}) tripActions.loadReservations(tripId) } }, [tripId]) useEffect(() => { addonsApi.enabled().then(data => { const map = {} data.addons.forEach(a => { map[a.id] = true }) setEnabledAddons({ packing: !!map.packing, budget: !!map.budget, documents: !!map.documents, collab: !!map.collab }) if (data.collabFeatures) setCollabFeatures(data.collabFeatures) }).catch(() => {}) authApi.getAppConfig().then(config => { if (config.allowed_file_types) setAllowedFileTypes(config.allowed_file_types) }).catch(() => {}) }, []) const TRIP_TABS = [ { id: 'plan', label: t('trip.tabs.plan'), icon: Map }, { id: 'buchungen', label: t('trip.tabs.reservations'), shortLabel: t('trip.tabs.reservationsShort'), icon: Ticket }, ...(enabledAddons.packing ? [{ id: 'listen', label: t('trip.tabs.lists'), shortLabel: t('trip.tabs.listsShort'), icon: PackageCheck }] : []), ...(enabledAddons.budget ? [{ id: 'finanzplan', label: t('trip.tabs.budget'), icon: Wallet }] : []), ...(enabledAddons.documents ? [{ id: 'dateien', label: t('trip.tabs.files'), icon: FolderOpen }] : []), ...(enabledAddons.collab ? [{ id: 'collab', label: t('admin.addons.catalog.collab.name'), icon: Users }] : []), ] const [activeTab, setActiveTab] = useState(() => { const saved = sessionStorage.getItem(`trip-tab-${tripId}`) return saved || 'plan' }) useEffect(() => { const validTabIds = TRIP_TABS.map(t => t.id) if (!validTabIds.includes(activeTab)) { setActiveTab('plan') sessionStorage.setItem(`trip-tab-${tripId}`, 'plan') } }, [enabledAddons]) const handleTabChange = (tabId: string): void => { setActiveTab(tabId) sessionStorage.setItem(`trip-tab-${tripId}`, tabId) if (tabId === 'finanzplan') tripActions.loadBudgetItems?.(tripId) if (tabId === 'dateien' && (!files || files.length === 0)) tripActions.loadFiles?.(tripId) } const { leftWidth, rightWidth, leftCollapsed, rightCollapsed, setLeftCollapsed, setRightCollapsed, startResizeLeft, startResizeRight } = useResizablePanels() const { selectedPlaceId, selectedAssignmentId, setSelectedPlaceId, selectAssignment } = usePlaceSelection() const [showDayDetail, setShowDayDetail] = useState(null) const [dayDetailCollapsed, setDayDetailCollapsed] = useState(false) const [showPlaceForm, setShowPlaceForm] = useState(false) const [editingPlace, setEditingPlace] = useState(null) const [prefillCoords, setPrefillCoords] = useState<{ lat: number; lng: number; name?: string; address?: string } | null>(null) const [editingAssignmentId, setEditingAssignmentId] = useState(null) const [showTripForm, setShowTripForm] = useState(false) const [showMembersModal, setShowMembersModal] = useState(false) const [showReservationModal, setShowReservationModal] = useState(false) const [editingReservation, setEditingReservation] = useState(null) const [fitKey, setFitKey] = useState(0) const [mobileSidebarOpen, setMobileSidebarOpen] = useState<'left' | 'right' | null>(null) const [deletePlaceId, setDeletePlaceId] = useState(null) const [deletePlaceIds, setDeletePlaceIds] = useState(null) const [isMobile, setIsMobile] = useState(() => window.innerWidth < 768) useEffect(() => { const mq = window.matchMedia('(max-width: 767px)') const handler = (e: MediaQueryListEvent) => setIsMobile(e.matches) mq.addEventListener('change', handler) return () => mq.removeEventListener('change', handler) }, []) // Start photo fetches during splash screen so images are ready when map mounts useEffect(() => { if (isLoading || !places || places.length === 0 || !placesPhotosEnabled) return for (const p of places) { if (p.image_url) continue const cacheKey = p.google_place_id || p.osm_id || `${p.lat},${p.lng}` if (!cacheKey || getCached(cacheKey)) continue const photoId = p.google_place_id || p.osm_id if (photoId || (p.lat && p.lng)) { fetchPhoto(cacheKey, photoId || `coords:${p.lat}:${p.lng}`, p.lat, p.lng, p.name) } } }, [isLoading, places]) // Load trip + files (needed for place inspector file section) useEffect(() => { if (tripId) { tripActions.loadTrip(tripId).catch(() => { toast.error(t('trip.toast.loadError')); navigate('/dashboard') }) tripActions.loadFiles(tripId) loadAccommodations() if (!navigator.onLine) { offlineDb.tripMembers.where('tripId').equals(Number(tripId)).toArray() .then(rows => setTripMembers(rows)) .catch(() => {}) } else { tripsApi.getMembers(tripId).then(d => { const all = [d.owner, ...(d.members || [])].filter(Boolean) setTripMembers(all) }).catch(() => {}) } } }, [tripId]) useEffect(() => { if (tripId) tripActions.loadReservations(tripId) }, [tripId]) useTripWebSocket(tripId) const [mapCategoryFilter, setMapCategoryFilter] = useState>(new Set()) const [mapPlacesFilter, setMapPlacesFilter] = useState('all') const [expandedDayIds, setExpandedDayIds] = useState | null>(null) const mapPlaces = useMemo(() => { // Build set of place IDs assigned to collapsed days const hiddenPlaceIds = new Set() if (expandedDayIds) { for (const [dayId, dayAssignments] of Object.entries(assignments)) { if (!expandedDayIds.has(Number(dayId))) { for (const a of dayAssignments) { if (a.place?.id) hiddenPlaceIds.add(a.place.id) } } } // Don't hide places that are also assigned to an expanded day for (const [dayId, dayAssignments] of Object.entries(assignments)) { if (expandedDayIds.has(Number(dayId))) { for (const a of dayAssignments) { hiddenPlaceIds.delete(a.place?.id) } } } } // Build set of planned place IDs for unplanned filter const plannedIds = mapPlacesFilter === 'unplanned' ? new Set(Object.values(assignments).flatMap(da => da.map(a => a.place?.id).filter(Boolean))) : null return places.filter(p => { if (!p.lat || !p.lng) return false if (mapPlacesFilter === 'tracks' && !p.route_geometry) return false if (mapCategoryFilter.size > 0) { if (p.category_id == null) { if (!mapCategoryFilter.has('uncategorized')) return false } else if (!mapCategoryFilter.has(String(p.category_id))) return false } if (hiddenPlaceIds.has(p.id)) return false if (plannedIds && plannedIds.has(p.id)) return false return true }) }, [places, mapCategoryFilter, mapPlacesFilter, assignments, expandedDayIds]) const { route, routeSegments, routeInfo, setRoute, setRouteInfo, updateRouteForDay } = useRouteCalculation({ assignments } as any, selectedDayId) const handleSelectDay = useCallback((dayId, skipFit) => { const changed = dayId !== selectedDayId tripActions.setSelectedDay(dayId) if (changed && !skipFit) setFitKey(k => k + 1) setMobileSidebarOpen(null) updateRouteForDay(dayId) }, [updateRouteForDay, selectedDayId]) const handlePlaceClick = useCallback((placeId, assignmentId) => { if (assignmentId) { selectAssignment(assignmentId, placeId) } else { setSelectedPlaceId(placeId) } if (placeId) { setShowDayDetail(null); setLeftCollapsed(false); setRightCollapsed(false) } }, [selectAssignment, setSelectedPlaceId]) const handleMarkerClick = useCallback((placeId) => { const opening = placeId !== undefined setSelectedPlaceId(prev => prev === placeId ? null : placeId) if (opening) { setLeftCollapsed(false); setRightCollapsed(false) } }, []) const handleMapClick = useCallback(() => { setSelectedPlaceId(null) }, []) const handleMapContextMenu = useCallback(async (e) => { if (!can('place_edit', trip)) return e.originalEvent?.preventDefault() const { lat, lng } = e.latlng setPrefillCoords({ lat, lng }) setEditingPlace(null) setEditingAssignmentId(null) setShowPlaceForm(true) try { const { mapsApi } = await import('../api/client') const data = await mapsApi.reverse(lat, lng, language) if (data.name || data.address) { setPrefillCoords(prev => prev ? { ...prev, name: data.name || '', address: data.address || '' } : prev) } } catch { /* best effort */ } }, [language]) const handleSavePlace = useCallback(async (data) => { const pendingFiles = data._pendingFiles delete data._pendingFiles if (editingPlace) { // Always strip time fields from place update — time is per-assignment only const { place_time, end_time, ...placeData } = data await tripActions.updatePlace(tripId, editingPlace.id, placeData) // If editing from assignment context, save time per-assignment if (editingAssignmentId) { await assignmentsApi.updateTime(tripId, editingAssignmentId, { place_time: place_time || null, end_time: end_time || null }) await tripActions.refreshDays(tripId) } // Upload pending files with place_id if (pendingFiles?.length > 0) { for (const file of pendingFiles) { const fd = new FormData() fd.append('file', file) fd.append('place_id', editingPlace.id) try { await tripActions.addFile(tripId, fd) } catch {} } } toast.success(t('trip.toast.placeUpdated')) } else { const place = await tripActions.addPlace(tripId, data) if (pendingFiles?.length > 0 && place?.id) { for (const file of pendingFiles) { const fd = new FormData() fd.append('file', file) fd.append('place_id', place.id) try { await tripActions.addFile(tripId, fd) } catch {} } } toast.success(t('trip.toast.placeAdded')) if (place?.id) { const capturedId = place.id pushUndo(t('undo.addPlace'), async () => { await tripActions.deletePlace(tripId, capturedId) }) } } }, [editingPlace, editingAssignmentId, tripId, toast, pushUndo]) const handleDeletePlace = useCallback((placeId) => { setDeletePlaceId(placeId) }, []) const confirmDeletePlace = useCallback(async () => { if (!deletePlaceId) return const state = useTripStore.getState() const capturedPlace = state.places.find(p => p.id === deletePlaceId) const capturedAssignments = Object.entries(state.assignments).flatMap(([dayId, as]) => as.filter(a => a.place?.id === deletePlaceId).map(a => ({ dayId: Number(dayId), orderIndex: a.order_index })) ) try { await tripActions.deletePlace(tripId, deletePlaceId) if (selectedPlaceId === deletePlaceId) setSelectedPlaceId(null) updateRouteForDay(selectedDayId) toast.success(t('trip.toast.placeDeleted')) if (capturedPlace) { pushUndo(t('undo.deletePlace'), async () => { const newPlace = await tripActions.addPlace(tripId, { name: capturedPlace.name, description: capturedPlace.description, lat: capturedPlace.lat, lng: capturedPlace.lng, address: capturedPlace.address, category_id: capturedPlace.category_id, icon: capturedPlace.icon, price: capturedPlace.price, }) for (const { dayId, orderIndex } of capturedAssignments) { await tripActions.assignPlaceToDay(tripId, dayId, newPlace.id, orderIndex) } }) } } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } }, [deletePlaceId, tripId, toast, selectedPlaceId, selectedDayId, updateRouteForDay, pushUndo]) const confirmDeletePlaces = useCallback(async (ids?: number[]) => { const targetIds = ids ?? deletePlaceIds if (!targetIds?.length) return const state = useTripStore.getState() const capturedPlaces = state.places.filter(p => targetIds.includes(p.id)) const capturedAssignments = Object.entries(state.assignments).flatMap(([dayId, as]) => as.filter(a => a.place?.id != null && targetIds.includes(a.place.id)).map(a => ({ dayId: Number(dayId), placeId: a.place!.id, orderIndex: a.order_index })) ) try { await tripActions.deletePlacesMany(tripId, targetIds) if (selectedPlaceId != null && targetIds.includes(selectedPlaceId)) setSelectedPlaceId(null) if (!ids) setDeletePlaceIds(null) updateRouteForDay(selectedDayId) toast.success(t('trip.toast.placesDeleted', { count: capturedPlaces.length })) if (capturedPlaces.length > 0) { pushUndo(t('undo.deletePlaces'), async () => { for (const place of capturedPlaces) { const newPlace = await tripActions.addPlace(tripId, { name: place.name, description: place.description, lat: place.lat, lng: place.lng, address: place.address, category_id: place.category_id, icon: place.icon, price: place.price, }) for (const a of capturedAssignments.filter(x => x.placeId === place.id)) { await tripActions.assignPlaceToDay(tripId, a.dayId, newPlace.id, a.orderIndex) } } }) } } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } }, [deletePlaceIds, tripId, toast, selectedPlaceId, selectedDayId, updateRouteForDay, pushUndo]) const handleAssignToDay = useCallback(async (placeId, dayId, position) => { const target = dayId || selectedDayId if (!target) { toast.error(t('trip.toast.selectDay')); return } try { const assignment = await tripActions.assignPlaceToDay(tripId, target, placeId, position) toast.success(t('trip.toast.assignedToDay')) updateRouteForDay(target) if (assignment?.id) { const capturedAssignmentId = assignment.id const capturedTarget = target pushUndo(t('undo.assignPlace'), async () => { await tripActions.removeAssignment(tripId, capturedTarget, capturedAssignmentId) }) } } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } }, [selectedDayId, tripId, toast, updateRouteForDay, pushUndo]) const handleRemoveAssignment = useCallback(async (dayId, assignmentId) => { const state = useTripStore.getState() const capturedAssignment = (state.assignments[String(dayId)] || []).find(a => a.id === assignmentId) const capturedPlaceId = capturedAssignment?.place?.id const capturedOrderIndex = capturedAssignment?.order_index ?? 0 try { await tripActions.removeAssignment(tripId, dayId, assignmentId) updateRouteForDay(dayId) if (capturedPlaceId != null) { const capturedDayId = dayId const capturedPos = capturedOrderIndex pushUndo(t('undo.removeAssignment'), async () => { await tripActions.assignPlaceToDay(tripId, capturedDayId, capturedPlaceId, capturedPos) }) } } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } }, [tripId, toast, updateRouteForDay, pushUndo]) const handleReorder = useCallback((dayId, orderedIds) => { const prevIds = (useTripStore.getState().assignments[String(dayId)] || []) .slice().sort((a, b) => a.order_index - b.order_index).map(a => a.id) try { tripActions.reorderAssignments(tripId, dayId, orderedIds) .then(() => { const capturedDayId = dayId const capturedPrevIds = prevIds pushUndo(t('undo.reorder'), async () => { await tripActions.reorderAssignments(tripId, capturedDayId, capturedPrevIds) }) }) .catch(() => {}) // Update route immediately from orderedIds const dayItems = useTripStore.getState().assignments[String(dayId)] || [] const ordered = orderedIds.map(id => dayItems.find(a => a.id === id)).filter(Boolean) const waypoints = ordered.map(a => a.place).filter(p => p?.lat && p?.lng) if (waypoints.length >= 2) setRoute(waypoints.map(p => [p.lat, p.lng])) else setRoute(null) setRouteInfo(null) } catch { toast.error(t('trip.toast.reorderError')) } }, [tripId, toast, pushUndo]) const handleUpdateDayTitle = useCallback(async (dayId, title) => { try { await tripActions.updateDayTitle(tripId, dayId, title) } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } }, [tripId, toast]) const handleSaveReservation = async (data) => { try { if (editingReservation) { const r = await tripActions.updateReservation(tripId, editingReservation.id, { ...data, day_id: selectedDayId || null }) toast.success(t('trip.toast.reservationUpdated')) setShowReservationModal(false) if (data.type === 'hotel') { accommodationsApi.list(tripId).then(d => setTripAccommodations(d.accommodations || [])).catch(() => {}) } return r } else { const r = await tripActions.addReservation(tripId, { ...data, day_id: selectedDayId || null }) toast.success(t('trip.toast.reservationAdded')) setShowReservationModal(false) // Refresh accommodations if hotel was created if (data.type === 'hotel') { accommodationsApi.list(tripId).then(d => setTripAccommodations(d.accommodations || [])).catch(() => {}) } return r } } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } } const handleDeleteReservation = async (id) => { try { await tripActions.deleteReservation(tripId, id) toast.success(t('trip.toast.deleted')) // Refresh accommodations in case a hotel booking was deleted accommodationsApi.list(tripId).then(d => setTripAccommodations(d.accommodations || [])).catch(() => {}) } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } } const selectedPlace = selectedPlaceId ? places.find(p => p.id === selectedPlaceId) : null // Build placeId → order-number map from the selected day's assignments const dayOrderMap = useMemo(() => { if (!selectedDayId) return {} const da = assignments[String(selectedDayId)] || [] const sorted = [...da].sort((a, b) => a.order_index - b.order_index) const map = {} sorted.forEach((a, i) => { if (!a.place?.id) return if (!map[a.place.id]) map[a.place.id] = [] map[a.place.id].push(i + 1) }) return map }, [selectedDayId, assignments]) // Places assigned to selected day (with coords) — used for map fitting const dayPlaces = useMemo(() => { if (!selectedDayId) return [] const da = assignments[String(selectedDayId)] || [] return da.map(a => a.place).filter(p => p?.lat && p?.lng) }, [selectedDayId, assignments]) const mapTileUrl = settings.map_tile_url || 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png' const defaultCenter = [settings.default_lat || 48.8566, settings.default_lng || 2.3522] const defaultZoom = settings.default_zoom || 10 const fontStyle = { fontFamily: "-apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif" } // Splash screen — show for initial load + a brief moment for photos to start loading const [splashDone, setSplashDone] = useState(false) useEffect(() => { if (!isLoading && trip) { const timer = setTimeout(() => setSplashDone(true), 1500) return () => clearTimeout(timer) } }, [isLoading, trip]) if (isLoading || !splashDone) { return (
Loading
{trip?.title || 'TREK'}
{t('trip.loadingPhotos')}
{[0, 1, 2].map(i => (
))}
) } if (!trip) return null return (
navigate('/dashboard')} onShare={() => setShowMembersModal(true)} />
{TRIP_TABS.map(tab => { const isActive = activeTab === tab.id const TabIcon = tab.icon return ( ) })}
{/* Offset by navbar + tab bar (44px) */}
{activeTab === 'plan' && (
{ if (r) { setRoute(r.coordinates); setRouteInfo({ distance: r.distanceText, duration: r.durationText, walkingText: r.walkingText, drivingText: r.drivingText }) } else { setRoute(null); setRouteInfo(null) } }} reservations={reservations} onAddReservation={(dayId) => { setEditingReservation(null); tripActions.setSelectedDay(dayId); setShowReservationModal(true) }} onDayDetail={(day) => { setShowDayDetail(day); setSelectedPlaceId(null); selectAssignment(null) }} onRemoveAssignment={handleRemoveAssignment} onEditPlace={(place, assignmentId) => { setEditingPlace(place); setEditingAssignmentId(assignmentId || null); setShowPlaceForm(true) }} onDeletePlace={(placeId) => handleDeletePlace(placeId)} accommodations={tripAccommodations} onNavigateToFiles={() => handleTabChange('dateien')} onExpandedDaysChange={setExpandedDayIds} pushUndo={pushUndo} canUndo={canUndo} lastActionLabel={lastActionLabel} onUndo={handleUndo} /> {!leftCollapsed && (
e.currentTarget.style.background = 'rgba(0,0,0,0.08)'} onMouseLeave={e => e.currentTarget.style.background = 'transparent'} /> )}
{!rightCollapsed && (
e.currentTarget.style.background = 'rgba(0,0,0,0.08)'} onMouseLeave={e => e.currentTarget.style.background = 'transparent'} /> )}
{ setEditingPlace(null); setShowPlaceForm(true) }} onAssignToDay={handleAssignToDay} onEditPlace={(place) => { setEditingPlace(place); setEditingAssignmentId(null); setShowPlaceForm(true) }} onDeletePlace={(placeId) => handleDeletePlace(placeId)} onBulkDeletePlaces={(ids) => setDeletePlaceIds(ids)} onCategoryFilterChange={setMapCategoryFilter} onPlacesFilterChange={setMapPlacesFilter} pushUndo={pushUndo} />
{/* Mobile sidebar buttons — portal to body to escape Leaflet touch handling */} {activeTab === 'plan' && !mobileSidebarOpen && !showPlaceForm && !showMembersModal && !showReservationModal && ReactDOM.createPortal(
, document.body )} {showDayDetail && !selectedPlace && (() => { const currentDay = days.find(d => d.id === showDayDetail.id) || showDayDetail const dayAssignments = assignments[String(currentDay.id)] || [] const geoPlace = dayAssignments.find(a => a.place?.lat && a.place?.lng)?.place || places.find(p => p.lat && p.lng) return ( { setShowDayDetail(null); handleSelectDay(null) }} onAccommodationChange={loadAccommodations} leftWidth={isMobile ? 0 : (leftCollapsed ? 0 : leftWidth)} rightWidth={isMobile ? 0 : (rightCollapsed ? 0 : rightWidth)} collapsed={dayDetailCollapsed} onToggleCollapse={() => setDayDetailCollapsed(c => !c)} /> ) })()} {selectedPlace && !isMobile && ( setSelectedPlaceId(null)} onEdit={() => { if (selectedAssignmentId) { const assignmentObj = Object.values(assignments).flat().find(a => a.id === selectedAssignmentId) const placeWithAssignmentTimes = assignmentObj?.place ? { ...selectedPlace, place_time: assignmentObj.place.place_time, end_time: assignmentObj.place.end_time } : selectedPlace setEditingPlace(placeWithAssignmentTimes) } else { setEditingPlace(selectedPlace) } setEditingAssignmentId(selectedAssignmentId || null) setShowPlaceForm(true) }} onDelete={() => handleDeletePlace(selectedPlace.id)} onAssignToDay={handleAssignToDay} onRemoveAssignment={handleRemoveAssignment} files={files} onFileUpload={canUploadFiles ? (fd) => tripActions.addFile(tripId, fd) : undefined} tripMembers={tripMembers} onSetParticipants={async (assignmentId, dayId, userIds) => { try { const data = await assignmentsApi.setParticipants(tripId, assignmentId, userIds) useTripStore.setState(state => ({ assignments: { ...state.assignments, [String(dayId)]: (state.assignments[String(dayId)] || []).map(a => a.id === assignmentId ? { ...a, participants: data.participants } : a ), } })) } catch {} }} onUpdatePlace={async (placeId, data) => { try { await tripActions.updatePlace(tripId, placeId, data) } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } }} leftWidth={(isMobile || window.innerWidth < 900) ? 0 : (leftCollapsed ? 0 : leftWidth)} rightWidth={(isMobile || window.innerWidth < 900) ? 0 : (rightCollapsed ? 0 : rightWidth)} /> )} {selectedPlace && isMobile && ReactDOM.createPortal(
setSelectedPlaceId(null)}>
e.stopPropagation()}> setSelectedPlaceId(null)} onEdit={() => { if (selectedAssignmentId) { const assignmentObj = Object.values(assignments).flat().find(a => a.id === selectedAssignmentId) const placeWithAssignmentTimes = assignmentObj?.place ? { ...selectedPlace, place_time: assignmentObj.place.place_time, end_time: assignmentObj.place.end_time } : selectedPlace setEditingPlace(placeWithAssignmentTimes) } else { setEditingPlace(selectedPlace) } setEditingAssignmentId(selectedAssignmentId || null) setShowPlaceForm(true) setSelectedPlaceId(null) }} onDelete={() => { handleDeletePlace(selectedPlace.id); setSelectedPlaceId(null) }} onAssignToDay={handleAssignToDay} onRemoveAssignment={handleRemoveAssignment} files={files} onFileUpload={canUploadFiles ? (fd) => tripActions.addFile(tripId, fd) : undefined} tripMembers={tripMembers} onSetParticipants={async (assignmentId, dayId, userIds) => { try { const data = await assignmentsApi.setParticipants(tripId, assignmentId, userIds) useTripStore.setState(state => ({ assignments: { ...state.assignments, [String(dayId)]: (state.assignments[String(dayId)] || []).map(a => a.id === assignmentId ? { ...a, participants: data.participants } : a ), } })) } catch {} }} onUpdatePlace={async (placeId, data) => { try { await tripActions.updatePlace(tripId, placeId, data) } catch (err: unknown) { toast.error(err instanceof Error ? err.message : t('common.unknownError')) } }} leftWidth={0} rightWidth={0} />
, document.body )} {mobileSidebarOpen && ReactDOM.createPortal(
setMobileSidebarOpen(null)}>
e.stopPropagation()}>
{mobileSidebarOpen === 'left' ? t('trip.mobilePlan') : t('trip.mobilePlaces')}
{mobileSidebarOpen === 'left' ? { handleSelectDay(id); setMobileSidebarOpen(null) }} onPlaceClick={(placeId, assignmentId) => { handlePlaceClick(placeId, assignmentId); setMobileSidebarOpen(null) }} onReorder={handleReorder} onUpdateDayTitle={handleUpdateDayTitle} onAssignToDay={handleAssignToDay} onRouteCalculated={(r) => { if (r) { setRoute(r.coordinates); setRouteInfo({ distance: r.distanceText, duration: r.durationText }) } }} reservations={reservations} onAddReservation={(dayId) => { setEditingReservation(null); tripActions.setSelectedDay(dayId); setShowReservationModal(true); setMobileSidebarOpen(null) }} onAddPlace={() => { setEditingPlace(null); setShowPlaceForm(true); setMobileSidebarOpen(null) }} onDayDetail={(day) => { setShowDayDetail(day); setSelectedPlaceId(null); selectAssignment(null); setMobileSidebarOpen(null) }} accommodations={tripAccommodations} onNavigateToFiles={() => { setMobileSidebarOpen(null); handleTabChange('dateien') }} onExpandedDaysChange={setExpandedDayIds} pushUndo={pushUndo} canUndo={canUndo} lastActionLabel={lastActionLabel} onUndo={handleUndo} /> : { handlePlaceClick(placeId); setMobileSidebarOpen(null) }} onAddPlace={() => { setEditingPlace(null); setShowPlaceForm(true); setMobileSidebarOpen(null) }} onAssignToDay={handleAssignToDay} onEditPlace={(place) => { setEditingPlace(place); setEditingAssignmentId(null); setShowPlaceForm(true); setMobileSidebarOpen(null) }} onDeletePlace={(placeId) => handleDeletePlace(placeId)} onBulkDeletePlaces={(ids) => setDeletePlaceIds(ids)} onBulkDeleteConfirm={(ids) => confirmDeletePlaces(ids)} days={days} isMobile onCategoryFilterChange={setMapCategoryFilter} onPlacesFilterChange={setMapPlacesFilter} pushUndo={pushUndo} /> }
, document.body )}
)} {activeTab === 'buchungen' && (
{ setEditingReservation(null); setShowReservationModal(true) }} onEdit={(r) => { setEditingReservation(r); setShowReservationModal(true) }} onDelete={handleDeleteReservation} onNavigateToFiles={() => handleTabChange('dateien')} />
)} {activeTab === 'listen' && (
)} {activeTab === 'finanzplan' && (
)} {activeTab === 'dateien' && (
tripActions.addFile(tripId, fd)} onDelete={(id) => tripActions.deleteFile(tripId, id)} onUpdate={(id, data) => tripActions.loadFiles(tripId)} places={places} days={days} assignments={assignments} reservations={reservations} tripId={tripId} allowedFileTypes={allowedFileTypes} />
)} {activeTab === 'collab' && (
)}
{ setShowPlaceForm(false); setEditingPlace(null); setEditingAssignmentId(null); setPrefillCoords(null) }} onSave={handleSavePlace} place={editingPlace} prefillCoords={prefillCoords} assignmentId={editingAssignmentId} dayAssignments={editingAssignmentId ? Object.values(assignments).flat() : []} tripId={tripId} categories={categories} onCategoryCreated={cat => tripActions.addCategory?.(cat)} /> setShowTripForm(false)} onSave={async (data) => { await tripActions.updateTrip(tripId, data); toast.success(t('trip.toast.tripUpdated')) }} trip={trip} /> setShowMembersModal(false)} tripId={tripId} tripTitle={trip?.title} /> { setShowReservationModal(false); setEditingReservation(null) }} onSave={handleSaveReservation} reservation={editingReservation} days={days} places={places} assignments={assignments} selectedDayId={selectedDayId} files={files} onFileUpload={canUploadFiles ? (fd) => tripActions.addFile(tripId, fd) : undefined} onFileDelete={(id) => tripActions.deleteFile(tripId, id)} accommodations={tripAccommodations} /> setDeletePlaceId(null)} onConfirm={confirmDeletePlace} title={t('common.delete')} message={t('trip.confirm.deletePlace')} /> setDeletePlaceIds(null)} onConfirm={confirmDeletePlaces} title={t('common.delete')} message={t('trip.confirm.deletePlaces', { count: deletePlaceIds?.length ?? 0 })} />
) }