import React, { useEffect, useState } from 'react' import { useParams, useNavigate, Link } from 'react-router-dom' import { useTripStore } from '../store/tripStore' import { tripsApi, daysApi, placesApi } from '../api/client' import Navbar from '../components/Layout/Navbar' import PhotoGallery from '../components/Photos/PhotoGallery' import { ArrowLeft } from 'lucide-react' import { useTranslation } from '../i18n' import type { Trip, Day, Place, Photo } from '../types' export default function PhotosPage(): React.ReactElement { const { t } = useTranslation() const { id: tripId } = useParams<{ id: string }>() const navigate = useNavigate() const tripStore = useTripStore() const [trip, setTrip] = useState(null) const [days, setDays] = useState([]) const [places, setPlaces] = useState([]) const [photos, setPhotos] = useState([]) const [isLoading, setIsLoading] = useState(true) useEffect(() => { loadData() }, [tripId]) const loadData = async (): Promise => { setIsLoading(true) try { const [tripData, daysData, placesData] = await Promise.all([ tripsApi.get(tripId), daysApi.list(tripId), placesApi.list(tripId), ]) setTrip(tripData.trip) setDays(daysData.days) setPlaces(placesData.places) // Load photos await tripStore.loadPhotos(tripId) } catch (err: unknown) { navigate('/dashboard') } finally { setIsLoading(false) } } // Sync photos from store useEffect(() => { setPhotos(tripStore.photos) }, [tripStore.photos]) const handleUpload = async (formData: FormData): Promise => { await tripStore.addPhoto(tripId, formData) } const handleDelete = async (photoId: number): Promise => { await tripStore.deletePhoto(tripId, photoId) } const handleUpdate = async (photoId: number, data: Record): Promise => { await tripStore.updatePhoto(tripId, photoId, data) } if (isLoading) { return (
) } return (
navigate(`/trips/${tripId}`)} />
{/* Header */}
{t('common.backToPlanning')}

{t('photos.title')}

{t('photos.subtitle', { count: photos.length, trip: trip?.name })}

) }