'use client'; import Link from 'next/link'; import { SAMPLE_LISTING_SLUG } from '../lib/sampleListing'; import { useI18n } from './components/I18nProvider'; import { useEffect, useMemo, useState } from 'react'; type LatestListing = { id: string; title: string; slug: string; teaser: string | null; coverImage: string | null; city: string; region: string; isSample: boolean; }; export const dynamic = 'force-dynamic'; const highlights = [ { keyTitle: 'highlightQualityTitle', keyBody: 'highlightQualityBody', }, { keyTitle: 'highlightLocalTitle', keyBody: 'highlightLocalBody', }, { keyTitle: 'highlightApiTitle', keyBody: 'highlightApiBody', }, ]; export default function HomePage() { const { t } = useI18n(); const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000'; const apiBase = process.env.NEXT_PUBLIC_API_BASE || 'http://localhost:3000/api'; const appEnv = process.env.APP_ENV || 'local'; const appVersion = process.env.NEXT_PUBLIC_VERSION || 'dev'; const [latest, setLatest] = useState([]); const [activeIndex, setActiveIndex] = useState(0); const [loadingLatest, setLoadingLatest] = useState(false); const [paused, setPaused] = useState(false); useEffect(() => { setLoadingLatest(true); fetch('/api/listings?limit=8', { cache: 'no-store' }) .then((res) => res.json()) .then((data) => setLatest((data.listings ?? []).slice(0, 5))) .catch(() => setLatest([])) .finally(() => setLoadingLatest(false)); }, []); useEffect(() => { if (!latest.length || paused) return; const id = setInterval(() => { setActiveIndex((prev) => (prev + 1) % latest.length); }, 4200); return () => clearInterval(id); }, [latest, paused]); useEffect(() => { if (activeIndex >= latest.length) { setActiveIndex(0); } }, [activeIndex, latest.length]); const activeListing = useMemo(() => { if (!latest.length) return null; return latest[Math.min(activeIndex, latest.length - 1)]; }, [latest, activeIndex]); return (
{t('heroEyebrow')}

{t('heroTitle')}

{t('heroBody')}

{t('ctaViewSample')} {t('ctaBrowse')} {t('ctaHealth')}
{highlights.map((item) => (

{t(item.keyTitle as any)}

{t(item.keyBody as any)}

))}

{t('runtimeConfigTitle')}

{t('runtimeAppEnv')} {appEnv} {t('runtimeSiteUrl')} {siteUrl} {t('runtimeApiBase')} {apiBase} Version {appVersion}

{t('latestListingsTitle')}

{t('latestListingsLead')}

{t('ctaBrowse')}
{loadingLatest ? (

{t('loading')}

) : !activeListing ? (

{t('mapNoResults')}

) : (
setPaused(true)} onMouseLeave={() => setPaused(false)}>
{latest.map((item) => (
{item.coverImage ? ( {item.title} ) : (
)}
{item.city}, {item.region} {item.isSample ? {t('sampleBadge')} : null}

{item.title}

{item.teaser}

{t('openListing')}
))}
{latest.map((_, idx) => ( setActiveIndex(idx)} /> ))}
)}
); }