'use client' import { useEffect, useState } from 'react' import { useMarketplacePreferences } from '@/components/MarketplaceShell' import { cloneMarketplaceHomepageContent, resolveMarketplaceHomepageSections, type MarketplaceHomepageConfig, type MarketplaceHomepageSectionType, } from '@rentaldrivego/types' import { resolveBrowserAppUrl } from '@/lib/appUrls' const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:4000/api/v1' export default function HomeContent() { const { language } = useMarketplacePreferences() const [content, setContent] = useState(cloneMarketplaceHomepageContent()) const dict = content[language] const sections = resolveMarketplaceHomepageSections(dict.sections) const dashboardUrl = resolveBrowserAppUrl(process.env.NEXT_PUBLIC_DASHBOARD_URL ?? 'http://localhost:3001/dashboard') const starterSignupHref = `${dashboardUrl}/sign-up?plan=STARTER&billing=MONTHLY¤cy=MAD` useEffect(() => { let cancelled = false async function loadHomepageContent() { try { const res = await fetch(`${API_BASE}/site/platform/homepage`, { cache: 'no-store' }) const json = await res.json().catch(() => null) if (!res.ok || !json?.data || cancelled) return setContent(json.data as MarketplaceHomepageConfig) } catch { // Fall back to the shared defaults when the API is unavailable. } } loadHomepageContent() return () => { cancelled = true } }, []) function hasSection(section: MarketplaceHomepageSectionType) { return sections.includes(section) } return (
{hasSection('hero') ? (

{dict.heroKicker}

{dict.heroTitle}

{dict.heroBody}

{dict.metrics.map(({ value, label }) => (

{value}

{label}

))}
) : null} {hasSection('surface') ? (
{dict.surfaceLabel} {dict.liveLabel}

{dict.surfaceTitle}

{dict.surfaceBody}

{[ ['01', dict.trustedFleets], ['02', dict.brandedFlows], ['03', dict.multiTenant], ].map(([step, label]) => (
{step}

{label}

+
))}
) : null}
{hasSection('audiences') ?

{dict.companyKicker}

{dict.companyTitle}

{dict.companyBody}

{dict.renterKicker}

{dict.renterTitle}

{dict.renterBody}

: null}
{hasSection('pillars') ?
{dict.pillars.map(({ title, body }, index) => (

0{index + 1}

{title}

{body}

))}
: null} {(hasSection('features') || hasSection('steps')) ?
{hasSection('features') ? (

{dict.featureLabel}

{dict.features.map((item, index) => (
{index + 1}

{item}

))}
) :
} {hasSection('steps') ? (

{dict.readyKicker}

{dict.stepsTitle}

{dict.steps.map(({ step, title, body }) => (

{dict.stepLabel} {step}

{title}

{body}

))}
) :
}
: null} {hasSection('closing') ?

{dict.readyKicker}

{dict.readyTitle}

{dict.readyBody}

: null}
) }