import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { api, imageUrl } from '../api/client'; import type { TourSummary } from '../types'; import './ToursPopup.css'; interface Props { open: boolean; onClose: () => void; onSelectTour: (tourId: number) => void; } export default function ToursPopup({ open, onClose, onSelectTour }: Props) { const { t } = useTranslation('tours'); const [tours, setTours] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (!open) return; let cancelled = false; setLoading(true); setError(null); api .listPublishedTours() .then((data) => { if (!cancelled) setTours(data.tours); }) .catch((err) => { if (!cancelled) { setError(err instanceof Error ? err.message : t('loadFailed')); setTours([]); } }) .finally(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; }; }, [open, t]); if (!open) return null; return (
e.stopPropagation()} >

{t('popupTitle')}

{t('popupHint')}

{loading &&

{t('loading')}

} {error &&

{error}

} {!loading && !error && tours.length === 0 && (

{t('noPublished')}

)}
    {tours.map((tour) => { const cover = tour.coverThumbnailPath || tour.coverImagePath; return (
  • ); })}
); }