import { useState, useEffect } from 'react' import { useParams } from 'react-router-dom' import { shareApi } from '../../api/client' /** * Shared-trip (public) data hook — owns the token lookup, the read-only share * fetch and the view state (selected day, active tab, language picker). * SharedTripPage is a pure wiring container; the post-load derivations * (sortedDays, map places, …) stay in the page next to the JSX that uses them. * Behaviour is identical to the previous in-component logic. */ export function useSharedTrip() { const { token } = useParams<{ token: string }>() // The shared payload is an open-ended snapshot (trip, days, assignments, …), // matched 1:1 from the public share endpoint — kept loosely typed as before. const [data, setData] = useState(null) const [error, setError] = useState(false) const [selectedDay, setSelectedDay] = useState(null) const [activeTab, setActiveTab] = useState('plan') const [showLangPicker, setShowLangPicker] = useState(false) useEffect(() => { if (!token) return shareApi.getSharedTrip(token).then(setData).catch(() => setError(true)) }, [token]) return { data, error, selectedDay, setSelectedDay, activeTab, setActiveTab, showLangPicker, setShowLangPicker } }