'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; }; 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 [latest, setLatest] = useState([]); const [activeIndex, setActiveIndex] = useState(0); const [loadingLatest, setLoadingLatest] = useState(false); useEffect(() => { setLoadingLatest(true); fetch('/api/listings?limit=8', { cache: 'no-store' }) .then((res) => res.json()) .then((data) => setLatest(data.listings ?? [])) .catch(() => setLatest([])) .finally(() => setLoadingLatest(false)); }, []); useEffect(() => { if (!latest.length) return; const id = setInterval(() => { setActiveIndex((prev) => (prev + 1) % latest.length); }, 4200); return () => clearInterval(id); }, [latest]); 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}

{t('latestListingsTitle')}

{t('latestListingsLead')}

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

{t('loading')}

) : !activeListing ? (

{t('mapNoResults')}

) : (
{activeListing.coverImage ? ( {activeListing.title} ) : (
)}
{activeListing.city}, {activeListing.region}

{activeListing.title}

{activeListing.teaser}

{t('openListing')}
{latest.map((item, idx) => ( ))}
)}
); }