'use client'; import { Building2, Calendar, Download, FileText, Grid3X3, Home, MapPin, Phone, } from 'lucide-react'; import Image from 'next/image'; import * as React from 'react'; import { ImageGallery } from '@/components/listings/image-gallery'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { formatPrice } from '@/lib/currency'; import { PROJECT_PROPERTY_TYPE_LABELS, PROJECT_STATUS_COLORS, PROJECT_STATUS_LABELS, duAnApi, type ProjectDetail, } from '@/lib/du-an-api'; import { cn } from '@/lib/utils'; type Tab = 'amenities' | 'location' | 'price' | 'listings' | 'documents'; const TABS: { key: Tab; label: string }[] = [ { key: 'amenities', label: 'Tiện ích' }, { key: 'location', label: 'Vị trí' }, { key: 'price', label: 'Giá' }, { key: 'listings', label: 'Tin đăng' }, { key: 'documents', label: 'Tài liệu' }, ]; interface DuAnDetailClientProps { project: ProjectDetail; } export function DuAnDetailClient({ project }: DuAnDetailClientProps) { const [activeTab, setActiveTab] = React.useState('amenities'); const [inquiryForm, setInquiryForm] = React.useState({ name: '', phone: '', message: '', }); const [inquiryState, setInquiryState] = React.useState< 'idle' | 'loading' | 'success' | 'error' >('idle'); const statusLabel = PROJECT_STATUS_LABELS[project.status]; const statusColor = PROJECT_STATUS_COLORS[project.status]; const handleInquirySubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!inquiryForm.name.trim() || !inquiryForm.phone.trim()) return; setInquiryState('loading'); try { await duAnApi.submitInquiry(project.id, { name: inquiryForm.name.trim(), phone: inquiryForm.phone.trim(), message: inquiryForm.message.trim(), }); setInquiryState('success'); } catch { setInquiryState('error'); } }; return (
{/* Header */}
{statusLabel} {project.propertyTypes.map((t) => ( {PROJECT_PROPERTY_TYPE_LABELS[t]} ))}

{project.name}

{project.address}, {project.district}, {project.city} {project.developer.name} {project.completionDate && ( Bàn giao: {new Date(project.completionDate).toLocaleDateString('vi-VN')} )}
{/* Gallery */} m.type === 'image') .map((m) => ({ id: m.id, type: 'image' as const, url: m.url, order: m.order, caption: m.caption }))} /> {/* Quick stats */}
} label="Tổng diện tích" value={`${project.totalArea.toLocaleString('vi-VN')} m²`} /> } label="Số căn" value={`${project.totalUnits}`} /> } label="Số block" value={`${project.blocks.length}`} />
{/* Main content */}
{/* Description */} Tổng quan dự án

{project.description}

{/* Blocks */} {project.blocks.length > 0 && ( Phân khu / Block
{project.blocks.map((block) => (

{block.name}

{block.totalUnits} căn {block.availableUnits} còn trống {block.floors} tầng
))}
)} {/* Tabs */}
{TABS.map((tab) => ( ))}
{activeTab === 'amenities' && } {activeTab === 'location' && } {activeTab === 'price' && } {activeTab === 'listings' && } {activeTab === 'documents' && }
{/* Sidebar */}
{/* Developer card */} Chủ đầu tư {project.developer.logoUrl ? ( {project.developer.name} ) : (
)}

{project.developer.name}

{project.developer.totalProjects} dự án

{/* Inquiry form */} Nhận tư vấn {inquiryState === 'success' ? (

Đã gửi thành công!

Chúng tôi sẽ liên hệ bạn sớm nhất.

) : (
{inquiryState === 'error' && (

Gửi thất bại. Vui lòng thử lại.

)}
setInquiryForm((f) => ({ ...f, name: e.target.value })) } required disabled={inquiryState === 'loading'} />
setInquiryForm((f) => ({ ...f, phone: e.target.value })) } required disabled={inquiryState === 'loading'} />