Repository Public
1// Verdict de prix : chaque loyer est comparé à sa juste valeur estimée2// (logements comparables du même segment).34import { cn } from "@/lib/cn";5import { fmtPct } from "@/lib/format";6import { useSeenOnce } from "@/lib/motion";78export type Verdict = "sous" | "marche" | "sur";910export const VERDICT: Record<Verdict, { label: string; long: string; tone: string; soft: string; color: string }> = {11 sous: { label: "Bon prix", long: "Sous le marché", tone: "text-good", soft: "bg-good-soft", color: "var(--good)" },12 marche: { label: "Prix juste", long: "Au prix du marché", tone: "text-fair", soft: "bg-fair-soft", color: "var(--fair)" },13 sur: { label: "Élevé", long: "Au-dessus du marché", tone: "text-high", soft: "bg-high-soft", color: "var(--high)" },14};1516/** Étiquette de verdict (fond teinté). */17export function VerdictPill({18 verdict,19 deviation,20 size = "sm",21 className,22}: {23 verdict: Verdict | null | undefined;24 deviation?: number | null;25 size?: "sm" | "md";26 /** conservé pour compatibilité : sans effet */27 solid?: boolean;28 className?: string;29}) {30 if (!verdict) return null;31 const v = VERDICT[verdict];32 return (33 <span34 className={cn(35 "inline-flex items-center gap-1.5 rounded-[6px] font-medium leading-none",36 size === "md" ? "px-2.5 py-1.5 text-[0.84rem]" : "px-2 py-1 text-[0.74rem]",37 v.soft,38 v.tone,39 className,40 )}41 >42 {v.label}43 {deviation != null && verdict !== "marche" && <span className="num">{fmtPct(deviation)}</span>}44 </span>45 );46}4748/** Étiquette posée sur une photographie : fond papier fixe, toujours lisible. */49export function VerdictTag({50 verdict,51 deviation,52 plain,53}: {54 verdict: Verdict | null | undefined;55 deviation?: number | null;56 /** hors photographie : texte seul, couleur du thème */57 plain?: boolean;58}) {59 if (!verdict || verdict === "marche") return null;60 const good = verdict === "sous";61 if (plain) {62 return (63 <span className={cn("num shrink-0 text-[0.78rem] font-medium", good ? "text-good" : "text-high")}>64 {VERDICT[verdict].label} {deviation != null && fmtPct(deviation)}65 </span>66 );67 }68 return (69 <span70 className="num inline-flex items-center gap-1 rounded-[6px] bg-white/92 px-1.5 py-1 text-[0.72rem] font-semibold leading-none"71 style={{ color: good ? "#245b48" : "#8f5d10" }}72 >73 {VERDICT[verdict].label}74 {deviation != null && <span className="font-medium">{fmtPct(deviation)}</span>}75 </span>76 );77}7879/** Jauge : position du loyer par rapport à la fourchette de juste valeur. */80export function FairValueGauge({81 price,82 fv,83 low,84 high,85 verdict,86}: {87 price: number;88 fv: number;89 low: number;90 high: number;91 verdict: Verdict | null | undefined;92}) {93 const span = Math.max(high - low, 1);94 const min = low - span * 0.45;95 const max = high + span * 0.45;96 const pos = (x: number) => `${Math.min(100, Math.max(0, ((x - min) / (max - min)) * 100))}%`;97 const color = verdict ? VERDICT[verdict].color : "var(--ink-3)";98 // le curseur part de la juste valeur et vient se poser sur le loyer99 const [ref, seen] = useSeenOnce<HTMLDivElement>();100 const at = seen ? price : fv;101 return (102 <div ref={ref} className="relative pb-6 pt-8">103 <div className="relative h-1.5 rounded-full bg-surface-3">104 <div className="absolute inset-y-0 origin-left rounded-full bg-ink-3/35 transition-transform duration-500 ease-[cubic-bezier(0.2,0.7,0.2,1)]" style={{ left: pos(low), right: `calc(100% - ${pos(high)})`, transform: seen ? "none" : "scaleX(0)" }} />105 <div className="absolute -top-1.5 h-4.5 w-px -translate-x-1/2 bg-ink" style={{ left: pos(fv) }} />106 <div107 className="absolute -top-[5px] size-4 -translate-x-1/2 rounded-full border-2 border-surface transition-[left] duration-700 ease-[cubic-bezier(0.3,1.45,0.5,1)]"108 style={{ left: pos(at), background: color }}109 />110 </div>111 <div className="num absolute top-0 -translate-x-1/2 whitespace-nowrap text-[0.72rem] font-medium transition-[left] duration-700 ease-[cubic-bezier(0.3,1.45,0.5,1)]" style={{ left: pos(at), color }}>112 Ce loyer113 </div>114 <div className="num absolute bottom-0 -translate-x-1/2 text-[0.7rem] text-ink-3" style={{ left: pos(low) }}>115 {Math.round(low)} $116 </div>117 <div className="num absolute bottom-0 -translate-x-1/2 text-[0.7rem] text-ink-3" style={{ left: pos(high) }}>118 {Math.round(high)} $119 </div>120 </div>121 );122}123