'use client'; import * as React from 'react'; import Link from 'next/link'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Select } from '@/components/ui/select'; import { ListingStatusBadge } from '@/components/listings/listing-status-badge'; import { listingsApi, type ListingDetail, type PaginatedResult } from '@/lib/listings-api'; import { PROPERTY_TYPES, TRANSACTION_TYPES } from '@/lib/validations/listings'; function formatPrice(priceVND: string): string { const num = Number(priceVND); 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 ListingsPage() { const [result, setResult] = React.useState | null>(null); const [loading, setLoading] = React.useState(true); const [filters, setFilters] = React.useState({ transactionType: '', propertyType: '', page: 1, }); React.useEffect(() => { setLoading(true); const params: Record = { page: filters.page, limit: 12 }; if (filters.transactionType) params['transactionType'] = filters.transactionType; if (filters.propertyType) params['propertyType'] = filters.propertyType; listingsApi .search(params) .then(setResult) .catch(() => setResult(null)) .finally(() => setLoading(false)); }, [filters]); return (

Tin đăng

{/* Filters */}
{/* Listing grid */} {loading ? (
) : !result || result.data.length === 0 ? (

Chưa có tin đăng nào

) : ( <>
{result.data.map((listing) => (
{listing.property.media.length > 0 ? ( {listing.property.title} ) : (
Chưa có ảnh
)}

{formatPrice(listing.priceVND)} VNĐ

{listing.property.title}

{listing.property.district}, {listing.property.city}

{listing.property.areaM2} m² {listing.property.bedrooms != null && ( {listing.property.bedrooms} PN )} {listing.property.bathrooms != null && listing.property.bathrooms > 0 && ( {listing.property.bathrooms} PT )}
))}
{/* Pagination */} {result.totalPages > 1 && (
Trang {result.page} / {result.totalPages}
)} )}
); }