'use client' import { useEffect, useRef, useState } from 'react' import Link from 'next/link' import Image from 'next/image' import { useVisitor } from '@/context/VisitorContext' import { t, tPlain } from '@/lib/i18n' import type { SectionDTO } from '@/lib/api/types' import LanguageSelector from '@/components/ui/LanguageSelector' interface Props { featuredEvent?: SectionDTO mainImageUrl?: string slug: string configurationId?: string } function formatDateRange(start?: string, end?: string, locale: string = 'fr'): string { if (!start) return '' const d1 = new Date(start) const d2 = end ? new Date(end) : null const opt: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'short' } if (!d2 || d1.toDateString() === d2.toDateString()) { return d1.toLocaleDateString(locale, opt) } return `${d1.toLocaleDateString(locale, opt)} → ${d2.toLocaleDateString(locale, opt)}` } export default function HomeHero({ featuredEvent, mainImageUrl, slug, configurationId }: Props) { const { language } = useVisitor() const heroRef = useRef(null) const [opacity, setOpacity] = useState(1) useEffect(() => { const onScroll = () => { if (!heroRef.current) return const heroHeight = heroRef.current.offsetHeight setOpacity(Math.max(0, 1 - window.scrollY / heroHeight)) } window.addEventListener('scroll', onScroll, { passive: true }) return () => window.removeEventListener('scroll', onScroll) }, []) const imageUrl = featuredEvent?.imageSource ?? mainImageUrl const isClickable = !!featuredEvent && !!configurationId const dateLabel = formatDateRange( featuredEvent?.event?.startDate, featuredEvent?.event?.endDate, language.toLowerCase() ) const inner = (
{imageUrl ? ( {featuredEvent ) : (
)}
{featuredEvent && (

{dateLabel && ( {dateLabel} )}

)}
) return (
{isClickable ? ( {inner} ) : ( inner )}
) }