'use client'; import { ArrowRight, ArrowRightLeft, Building2, Calculator, CheckCircle2, Factory, Home, MapPin, Users, type LucideIcon, } from 'lucide-react'; import { useTranslations } from 'next-intl'; import * as React from 'react'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Select } from '@/components/ui/select'; import { Link, useRouter } from '@/i18n/navigation'; import { transferApi, type TransferListingListItem } from '@/lib/chuyen-nhuong-api'; import { duAnApi, type ProjectSummary } from '@/lib/du-an-api'; import { industrialApi, type IndustrialParkListItem } from '@/lib/khu-cong-nghiep-api'; type FeatureKey = 'projects' | 'industrial' | 'transfer' | 'valuation'; const FEATURES: { key: FeatureKey; href: string; icon: LucideIcon }[] = [ { key: 'projects', href: '/du-an', icon: Building2 }, { key: 'industrial', href: '/khu-cong-nghiep', icon: Factory }, { key: 'transfer', href: '/chuyen-nhuong', icon: ArrowRightLeft }, { key: 'valuation', href: '/dashboard/valuation', icon: Calculator }, ]; type StatKey = 'listings' | 'users' | 'transactions' | 'provinces'; const STATS: { key: StatKey; value: string; icon: LucideIcon }[] = [ { key: 'listings', value: '10,000+', icon: Home }, { key: 'users', value: '50,000+', icon: Users }, { key: 'transactions', value: '2,000+', icon: CheckCircle2 }, { key: 'provinces', value: '63', icon: MapPin }, ]; const PROPERTY_TYPE_KEYS = ['APARTMENT', 'HOUSE', 'VILLA', 'LAND', 'OFFICE', 'SHOPHOUSE'] as const; const TRANSACTION_TYPE_KEYS = ['SALE', 'RENT'] as const; type FeaturedItem = { id: string; href: string; imageUrl: string | null; fallbackIcon: LucideIcon; title: string; location: string; priceLabel: string; meta: string[]; }; const VIEW_ALL_HREFS: Record = { projects: '/du-an', industrial: '/khu-cong-nghiep', transfer: '/chuyen-nhuong', valuation: '/dashboard/valuation', }; function formatVND(value: string | number | null | undefined): string { if (value == null) return '—'; const num = typeof value === 'string' ? Number(value) : value; if (!Number.isFinite(num) || num <= 0) return '—'; if (num >= 1_000_000_000) return `${(num / 1_000_000_000).toFixed(1)} tỷ`; if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(0)} triệu`; return num.toLocaleString('vi-VN'); } export default function LandingPage() { const router = useRouter(); const t = useTranslations(); const [searchQuery, setSearchQuery] = React.useState(''); const [transactionType, setTransactionType] = React.useState(''); const [propertyType, _setPropertyType] = React.useState(''); const [activeFeature, setActiveFeature] = React.useState('projects'); const [projects, setProjects] = React.useState([]); const [parks, setParks] = React.useState([]); const [transfers, setTransfers] = React.useState([]); const [loadingFeatured, setLoadingFeatured] = React.useState(true); const [featuredError, setFeaturedError] = React.useState(false); const fetchFeatured = React.useCallback((feature: FeatureKey) => { if (feature === 'valuation') { setLoadingFeatured(false); setFeaturedError(false); return; } setLoadingFeatured(true); setFeaturedError(false); const request = feature === 'projects' ? duAnApi.search({ limit: 4 }).then((res) => setProjects(res.data)) : feature === 'industrial' ? industrialApi.search({ limit: 4 }).then((res) => setParks(res.data)) : transferApi.search({ limit: 4 }).then((res) => setTransfers(res.data)); request .catch(() => setFeaturedError(true)) .finally(() => setLoadingFeatured(false)); }, []); React.useEffect(() => { fetchFeatured(activeFeature); }, [activeFeature, fetchFeatured]); const featuredItems: FeaturedItem[] = React.useMemo(() => { if (activeFeature === 'projects') { return projects.map((p) => ({ id: p.id, href: `/du-an/${p.slug}`, imageUrl: p.thumbnailUrl, fallbackIcon: Building2, title: p.name, location: `${p.district}, ${p.city}`, priceLabel: p.minPrice ? `Từ ${formatVND(p.minPrice)} VNĐ` : '—', meta: [p.developer.name, `${p.totalUnits} căn`].filter(Boolean) as string[], })); } if (activeFeature === 'industrial') { return parks.map((k) => ({ id: k.id, href: `/khu-cong-nghiep/${k.slug}`, imageUrl: null, fallbackIcon: Factory, title: k.name, location: k.province, priceLabel: k.landRentUsdM2Year ? `${k.landRentUsdM2Year} USD/m²/năm` : '—', meta: [`${k.totalAreaHa} ha`, `Lấp đầy ${Math.round(k.occupancyRate)}%`], })); } if (activeFeature === 'transfer') { return transfers.map((tr) => ({ id: tr.id, href: `/chuyen-nhuong/${tr.id}`, imageUrl: tr.media?.[0]?.url ?? null, fallbackIcon: ArrowRightLeft, title: tr.title, location: `${tr.district}, ${tr.city}`, priceLabel: `${formatVND(tr.askingPriceVND)} VNĐ`, meta: [tr.areaM2 ? `${tr.areaM2} m²` : null, `${tr.itemCount} món`].filter(Boolean) as string[], })); } return []; }, [activeFeature, projects, parks, transfers]); const handleSearch = (e: React.FormEvent) => { e.preventDefault(); const params = new URLSearchParams(); if (searchQuery) params.set('q', searchQuery); if (transactionType) params.set('transactionType', transactionType); if (propertyType) params.set('propertyType', propertyType); router.push(`/search?${params.toString()}`); }; return (
{/* Hero Section */}

{t('landing.heroTitle')} {t('landing.heroTitleHighlight')}

{t('landing.heroSubtitle')}

{/* Search Bar */}
setSearchQuery(e.target.value)} className="border-0 shadow-none focus-visible:ring-0" aria-label={t('landing.searchPlaceholder')} />
{/* Quick property type links */}
{PROPERTY_TYPE_KEYS.map((key) => ( {t(`propertyTypes.${key}`)} ))}
{/* Core Features */}

{t('landing.featuresTitle')}

{t('landing.featuresSubtitle')}

{FEATURES.map((feature) => (

{t(`landing.features.${feature.key}.title`)}

{t(`landing.features.${feature.key}.description`)}

{t('landing.features.explore')}
))}
{/* Featured Listings */}

{t('landing.featuredSubtitle')}

{/* Tabs */}
{FEATURES.map((feature) => ( ))}
{/* List */}
{activeFeature === 'valuation' ? ( ) : loadingFeatured ? (
) : featuredError ? (

{t('landing.loadError')}

) : featuredItems.length > 0 ? (
    {featuredItems.map((item) => (
  • {item.imageUrl ? ( // eslint-disable-next-line @next/next/no-img-element {item.title} ) : (
    )}

    {item.title}

    {item.meta.length > 0 ? (

    {item.meta.join(' • ')}

    ) : null}

    {item.priceLabel}

  • ))}
) : (

{t('landing.noFeatured')}

)}
{/* Market Stats */}

{t('landing.statsTitle')}

{t('landing.statsSubtitle')}

{STATS.map((stat) => (
))}
{/* CTA Section */}

{t('landing.ctaTitle')}

{t('landing.ctaSubtitle')}

); } function ValuationHighlight({ tReady, tDesc, tExplore, }: { tReady: string; tDesc: string; tExplore: string; }) { return (

{tReady}

{tDesc}

); }