import React from 'react'; import { AnimatePresence, motion } from 'framer-motion'; import { ChevronLeft, ChevronRight, Pause, Play, Maximize2, Minimize2 } from 'lucide-react'; import { useEventData } from '../context/EventDataContext'; import EventLogo from '../components/EventLogo'; import { fetchGallery, type GalleryPhoto } from '../services/photosApi'; import { useTranslation } from '@/guest/i18n/useTranslation'; function normalizeImageUrl(src?: string | null) { if (!src) return ''; if (/^https?:/i.test(src)) return src; let cleanPath = src.replace(/^\/+/g, '').replace(/\/+/g, '/'); if (!cleanPath.startsWith('storage/')) cleanPath = `storage/${cleanPath}`; return `/${cleanPath}`.replace(/\/+/g, '/'); } export default function SlideshowScreen() { const { token, event } = useEventData(); const { t } = useTranslation(); const [photos, setPhotos] = React.useState([]); const [index, setIndex] = React.useState(0); const [paused, setPaused] = React.useState(false); const [isFullscreen, setIsFullscreen] = React.useState(false); const intervalRef = React.useRef(null); React.useEffect(() => { document.body.classList.add('guest-immersive'); return () => { document.body.classList.remove('guest-immersive'); }; }, []); React.useEffect(() => { if (!token) return; let active = true; fetchGallery(token, { limit: 50 }) .then((response) => { if (!active) return; setPhotos(response.data ?? []); setIndex(0); }) .catch(() => { if (active) setPhotos([]); }); return () => { active = false; }; }, [token]); React.useEffect(() => { if (paused || photos.length <= 1) { if (intervalRef.current) window.clearInterval(intervalRef.current); return; } intervalRef.current = window.setInterval(() => { setIndex((prev) => (prev + 1) % photos.length); }, 5000); return () => { if (intervalRef.current) window.clearInterval(intervalRef.current); }; }, [paused, photos.length]); React.useEffect(() => { const handleFullscreen = () => setIsFullscreen(Boolean(document.fullscreenElement)); document.addEventListener('fullscreenchange', handleFullscreen); handleFullscreen(); return () => document.removeEventListener('fullscreenchange', handleFullscreen); }, []); const current = photos[index] as Record | undefined; const imageUrl = normalizeImageUrl( (current?.full_url as string | undefined) ?? (current?.thumbnail_url as string | undefined) ?? (current?.thumbnail_path as string | undefined) ?? (current?.file_path as string | undefined) ?? (current?.url as string | undefined) ?? (current?.image_url as string | undefined) ); const toggleFullscreen = async () => { try { if (!document.fullscreenElement) { await document.documentElement.requestFullscreen?.(); } else { await document.exitFullscreen?.(); } } catch (error) { console.warn('Fullscreen toggle failed', error); } }; return (
{event?.name ?? t('galleryPage.hero.eventFallback', 'Event')}
{t('galleryPage.title', 'Gallery')}
{imageUrl ? ( ) : null} {photos.length === 0 ? (

{t('galleryPublic.emptyTitle', 'Noch keine Fotos')}

{t('galleryPublic.emptyDescription', 'Sobald Fotos freigegeben sind, erscheinen sie hier.')}

) : null}
); }