Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/components/avendre/ListingCardView.tsx9 * Module : components10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-09-0812 * Last Modified : 2026-09-0813 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Vrai-Prix — carte d'annonce (liste « À vendre », voisines, comparables en vente).43"use client";44import Link from "next/link";45import type { ListingCard } from "@/lib/immoka";46import { TYPE_GROUPS } from "@/lib/listing-types";47import { money, num, pct, sqftToM2 } from "./fmt";4849export function groupLabel(key: string, fr: boolean): string {50 const g = TYPE_GROUPS.find((x) => x.key === key);51 return g ? (fr ? g.fr : g.en) : key;52}5354/** Pastille écart estimation vs prix demandé (encre = au-dessus, rouge = en-dessous). */55export function RatioPill({ ratio, fr, size = "sm" }: { ratio: number | null; fr: boolean; size?: "sm" | "md" }) {56 const cls = size === "md" ? "px-2.5 py-1 text-[11px]" : "px-1.5 py-0.5 text-[9.5px]";57 if (ratio == null)58 return (59 <span className={`vp-mono inline-block border border-[var(--line)] uppercase tracking-[0.06em] text-ink-3 ${cls}`}>60 {fr ? "non évaluée" : "not evaluated"}61 </span>62 );63 const d = (ratio - 1) * 100;64 const tone =65 Math.abs(d) < 566 ? "border-[var(--line-strong)] text-ink"67 : d > 068 ? "border-ink bg-ink text-paper"69 : "border-[var(--danger)] text-[var(--danger)]";70 return (71 <span className={`vp-mono inline-block border font-bold uppercase tracking-[0.06em] ${tone} ${cls}`} title={fr ? "Estimation Vrai-Prix vs prix demandé" : "Vrai-Prix estimate vs asking price"}>72 {fr ? "éval." : "est."} {pct(d, fr ? "fr" : "en")}73 </span>74 );75}7677/** Badge « Coût IA » — affiché seulement quand une analyse IA complète existe pour l'annonce (jamais avant). */78export function AiCostBadge({ rcn, fr }: { rcn: number | null; fr: boolean }) {79 return (80 <span className="vp-mono inline-block border border-[var(--accent)] px-1.5 py-0.5 text-[9.5px] font-bold uppercase tracking-[0.06em] text-[var(--accent-deep)]" title={fr ? "Analyse IA du bâtiment disponible" : "AI building analysis available"}>81 {rcn ? `RCN ${fr ? "estimé" : "est."} ${Math.round(rcn / 1000)} k$` : fr ? "Coût IA disponible" : "AI cost available"}82 </span>83 );84}8586export default function ListingCardView({ c, fr, compact = false, ai = null }: { c: ListingCard; fr: boolean; compact?: boolean; ai?: { rcn: number | null } | null }) {87 const lang = fr ? "fr" : "en";88 const area = sqftToM2(c.areaSqft);89 const facts = [90 c.bedrooms != null ? `${c.bedrooms} ${fr ? "ch." : "bd"}` : null,91 c.bathrooms != null ? `${c.bathrooms} ${fr ? "sdb" : "ba"}` : null,92 area ? `${num(area, lang)} m²` : null,93 c.yearBuilt ? `${c.yearBuilt}` : null,94 ].filter((x): x is string => x != null);95 return (96 <Link97 href={`/a-vendre/${encodeURIComponent(c.uid)}`}98 className="group flex flex-col border border-[var(--line)] bg-surface transition-colors hover:border-[var(--line-strong)]"99 >100 <div className={`relative w-full overflow-hidden bg-[var(--surface-2)] ${compact ? "aspect-[4/3]" : "aspect-[3/2]"}`}>101 {c.image ? (102 // eslint-disable-next-line @next/next/no-img-element103 <img104 src={c.image}105 alt=""106 loading="lazy"107 referrerPolicy="no-referrer"108 className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.02]"109 />110 ) : (111 <div className="vp-mono flex h-full w-full items-center justify-center text-[10px] uppercase tracking-[0.1em] text-ink-3">112 {fr ? "sans photo" : "no photo"}113 </div>114 )}115 <span className="vp-mono absolute left-2 top-2 bg-paper/95 px-1.5 py-0.5 text-[9.5px] uppercase tracking-[0.08em] text-ink-2">116 {groupLabel(c.group, fr)}117 </span>118 {c.nImages > 1 && (119 <span className="vp-mono absolute bottom-2 right-2 bg-ink/80 px-1.5 py-0.5 text-[9.5px] text-paper">120 {c.nImages} 📷121 </span>122 )}123 </div>124 <div className="flex flex-1 flex-col p-3">125 <div className="flex items-baseline justify-between gap-2">126 <p className="vp-display text-[19px] font-bold leading-none tracking-[-0.02em]">{money(c.price, lang)}</p>127 <span className="flex flex-wrap items-center justify-end gap-1">128 {ai ? <AiCostBadge rcn={ai.rcn} fr={fr} /> : null}129 <RatioPill ratio={c.ratio} fr={fr} />130 </span>131 </div>132 <p className="mt-2 truncate text-[13.5px] font-semibold leading-snug">{c.address || c.propertyType || "—"}</p>133 <p className="truncate text-[12px] text-ink-2">134 {[c.sector, c.municipalite ?? c.city].filter(Boolean).join(" · ")}135 </p>136 <p className="vp-mono mt-2 text-[10px] uppercase tracking-[0.05em] text-ink-3">137 {facts.length ? facts.join(" · ") : c.propertyType ?? ""}138 {c.distanceM != null ? ` · ${c.distanceM < 1000 ? `${c.distanceM} m` : `${(c.distanceM / 1000).toFixed(1)} km`}` : ""}139 </p>140 {c.est != null && (141 <p className="vp-mono mt-auto pt-2 text-[10px] uppercase tracking-[0.05em] text-ink-2">142 {fr ? "Vrai-Prix" : "Vrai-Prix"} <b className="text-ink">{money(c.est, lang)}</b>143 {c.confidence ? ` · ${fr ? "conf." : "conf."} ${c.confidence}` : ""}144 </p>145 )}146 </div>147 </Link>148 );149}150