'use client'; import { X } from 'lucide-react'; import Image from 'next/image'; import { useTranslations } from 'next-intl'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Link } from '@/i18n/navigation'; import { formatPrice, formatPricePerM2 } from '@/lib/currency'; import type { ListingDetail } from '@/lib/listings-api'; const PROPERTY_TYPE_LABELS: Record = { APARTMENT: 'Căn hộ', HOUSE: 'Nhà riêng', VILLA: 'Biệt thự', LAND: 'Đất nền', OFFICE: 'Văn phòng', SHOPHOUSE: 'Shophouse', }; const DIRECTION_LABELS: Record = { NORTH: 'Bắc', SOUTH: 'Nam', EAST: 'Đông', WEST: 'Tây', NORTHEAST: 'Đông Bắc', NORTHWEST: 'Tây Bắc', SOUTHEAST: 'Đông Nam', SOUTHWEST: 'Tây Nam', }; interface ComparisonTableProps { listings: ListingDetail[]; onRemove: (id: string) => void; } interface ComparisonRowProps { label: string; values: React.ReactNode[]; highlight?: boolean; } function ComparisonRow({ label, values, highlight }: ComparisonRowProps) { return ( {label} {values.map((val, i) => ( {val} ))} ); } export function ComparisonTable({ listings, onRemove }: ComparisonTableProps) { const t = useTranslations('compare'); if (listings.length === 0) return null; return (
{listings.map((listing) => ( ))} {/* Price */} ( {formatPrice(l.priceVND)} VND {l.transactionType === 'RENT' && l.rentPriceMonthly && ( /tháng )} ))} /> {/* Transaction type */} ( {l.transactionType === 'SALE' ? t('sale') : t('rent')} ))} /> {/* Property type */} ( {PROPERTY_TYPE_LABELS[l.property.propertyType] || l.property.propertyType} ))} /> {/* Area */} ( {l.property.areaM2} m² ))} /> {/* Price per m² */} ( {l.pricePerM2 != null ? formatPricePerM2(l.pricePerM2) : '—'} ))} /> {/* Bedrooms */} ( {l.property.bedrooms != null ? `${l.property.bedrooms} ${t('rooms')}` : '—'} ))} /> {/* Bathrooms */} ( {l.property.bathrooms != null ? `${l.property.bathrooms} ${t('rooms')}` : '—'} ))} /> {/* Direction */} ( {l.property.direction ? DIRECTION_LABELS[l.property.direction] || l.property.direction : '—'} ))} /> {/* Floors */} ( {l.property.floors != null ? l.property.floors : '—'} ))} /> {/* Year built */} ( {l.property.yearBuilt != null ? l.property.yearBuilt : '—'} ))} /> {/* Legal status */} ( {l.property.legalStatus || '—'} ))} /> {/* Location */} ( {l.property.address}, {l.property.district}, {l.property.city} ))} /> {/* Amenities */} (
{l.property.amenities && l.property.amenities.length > 0 ? l.property.amenities.map((a) => ( {a} )) : '—'}
))} /> {/* Project name */} ( {l.property.projectName || '—'} ))} />
{t('property')}
{/* Image */}
{listing.property.media.length > 0 ? ( {listing.property.title} ) : (
{t('noImage')}
)}
{/* Title */} {listing.property.title} {/* Remove button */}
); }