// ----------------------------------------------------------------------------- // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Project: Toit-Ka // components/ListingCard.tsx : carte d'annonce (grille) — bi-univers. // Le badge d'univers (Louer lime / Acheter rouge) garde la grille lisible // quand les deux univers se croisent (recherche unifiée, favoris). // ----------------------------------------------------------------------------- import { Link } from "react-router-dom"; import { Listing, fichePath, fmtArea, fmtPrice, sourceName } from "../api"; import { useAccount } from "../account"; import { Ico, IcoHeart } from "./Icons"; export default function ListingCard({ l, showTx = false }: { l: Listing; showTx?: boolean }) { const img = l.images && l.images.length > 0 ? l.images[0] : null; const { favs, toggleFav } = useAccount(); const fav = favs.has(l.uid); const louer = l.transaction_type === "louer"; const meta: { ico: string; txt: string }[] = []; if (l.bedrooms != null) meta.push({ ico: "bed", txt: `${l.bedrooms} ch.` }); if (l.bathrooms != null) meta.push({ ico: "bath", txt: `${l.bathrooms} sdb` }); const area = fmtArea(l.area_sqft); if (area) meta.push({ ico: "area", txt: area }); if (louer && l.pets === "oui") meta.push({ ico: "paw", txt: "animaux ok" }); if (louer && l.furnished === 1) meta.push({ ico: "sofa", txt: "meublé" }); const dispo = louer && l.availability_date ? (l.availability_date === "now" ? "Libre maintenant" : `Libre ${l.availability_date}`) : l.mls ? `MLS ${l.mls}` : ""; const price = l.price != null ? <>{l.price.toLocaleString("fr-CA", { maximumFractionDigits: 0 })} $ {louer && /mois} : <>{l.price_label || "Prix sur demande"}; return (
{img ? ( {l.title ) : (
)} {showTx ? {louer ? "À louer" : "À vendre"} : l.type && {l.type}} {l.images.length > 1 && ( {l.images.length} )}
{price}
{l.address || l.title}
{showTx && l.type && {l.type}} {showTx && l.type && (l.sector || l.city) && } {l.sector && {l.sector}} {l.sector && l.city && } {l.city && {l.city}}
{meta.length > 0 && (
{meta.map((m) => ( {m.txt} ))}
)}
{sourceName(l.source)} {dispo && {dispo}}
); }