SPB Git

Repository Public

Overview.tsx 26.1 KB 529 lines tsx

1// Aperçu : ce qu'on veut savoir en arrivant. Verdict, prix demandé, adresse,2// faits, actions ; puis le « vrai prix » expliqué (jauge, fourchette,3// évaluation municipale, historique). Résumé collant (grand écran) et barre4// d'action (mobile).56import type { ReactNode } from "react";7import { ArrowUpRight, Download, Heart, Scale, Share2 } from "lucide-react";8import {9  daysOnline, isRental, municipalValueOf, pdfUrl, placeOf, priceComparison, priceUsable, sourceLabel, titleOf, typeOf,10  type PriceComparison, type Property,11} from "@/lib/api.propriete";12import { cn } from "@/lib/cn";13import { fmtAgo, fmtInt } from "@/lib/format";14import { DrawOnView, Ticker, useSeenOnce } from "@/lib/motion";15import { toggleCompare, toggleFavorite, useCompare, useIsFavorite, type SavedListing } from "@/lib/store";16import { VerdictPill } from "@/components/Verdict";17import { buttonClass } from "@/ui/primitives";18import { toast } from "@/ui/toast";19import type { Finance } from "./Financing";20import { Disclosure, fmtDay, money, nbsp, Panel, pct0, Tile } from "./kit";2122export async function share(p: Property) {23  const url = window.location.href;24  const title = `${titleOf(p)} · Immo-Ka`;25  try {26    if (navigator.share) {27      await navigator.share({ title, url });28      return;29    }30    await navigator.clipboard.writeText(url);31    toast("Lien copié");32  } catch {33    /* partage annulé */34  }35}3637const plural = (n: number, one: string, many: string) => `${n} ${n > 1 ? many : one}`;38const ACRE = 43_560;39export const fmtArea = (sqft: number) => `${fmtInt(Math.round(sqft))}${nbsp}pi²`;40export const fmtLot = (sqft: number) => (sqft >= ACRE * 2 ? `${(sqft / ACRE).toLocaleString("fr-CA", { maximumFractionDigits: 1 })} acres` : fmtArea(sqft));41/** Superficie habitable crédible (certaines sources publient des mètres carrés ou une seule pièce). */42export const livingArea = (p: Property) => (p.area_sqft != null && p.area_sqft >= 200 && p.area_sqft < 60_000 ? p.area_sqft : null);4344/** « Maison · 3 chambres · 2 salles de bain · 1 500 pi² » */45export function specLine(p: Property): string {46  const area = livingArea(p);47  return [48    typeOf(p),49    p.bedrooms != null && p.bedrooms > 0 ? plural(Math.round(p.bedrooms), "chambre", "chambres") : null,50    p.bathrooms != null && p.bathrooms > 0 ? plural(p.bathrooms, "salle de bain", "salles de bain") : null,51    area ? fmtArea(area) : p.lot_sqft ? `terrain de ${fmtLot(p.lot_sqft)}` : null,52  ]53    .filter(Boolean)54    .join(" · ");55}5657export function statusOf(p: Property): { label: string; live: boolean } {58  if (p.active === 0) return { label: "Retirée du marché", live: false };59  const s = (p.status || "").toLowerCase();60  if (/vendu/.test(s)) return { label: "Vendue", live: false };61  if (/conditionnel|offre/.test(s)) return { label: "Offre acceptée", live: true };62  if (isRental(p)) return { label: "À louer", live: true };63  return { label: "À vendre", live: true };64}6566// --- Actions ------------------------------------------------------------------67const actionBase =68  "lk-press inline-flex h-11 shrink-0 items-center justify-center gap-2 rounded-[10px] border border-line-2 text-[0.86rem] font-medium text-ink transition-colors duration-150 hover:border-ink-3";69const action = `${actionBase} px-3.5`;70const actionIcon = `${actionBase} w-11`;7172function snapshot(p: Property): SavedListing {73  return {74    uid: p.uid,75    title: titleOf(p),76    address: p.address || "",77    city: p.city || "",78    sector: p.sector || "",79    unit_type: typeOf(p) || "",80    price: p.price,81    image: p.images?.[0] ?? null,82    source: p.source,83    savedAt: Date.now(),84  };85}8687/** Favori : le cœur, avec un léger rebond à l'ajout. Gardé dans le navigateur. */88export function SaveAction({ p, compact }: { p: Property; compact?: boolean }) {89  const fav = useIsFavorite(p.uid);90  return (91    <button92      type="button"93      aria-pressed={fav}94      aria-label={fav ? "Retirer des favoris" : "Ajouter aux favoris"}95      onClick={(e) => {96        const added = toggleFavorite(snapshot(p));97        const icon = e.currentTarget.querySelector("svg");98        if (added) icon?.animate([{ transform: "scale(1)" }, { transform: "scale(1.3)" }, { transform: "scale(1)" }], { duration: 260, easing: "cubic-bezier(0.2,0.7,0.2,1)" });99        toast(added ? "Ajoutée à vos favoris" : "Retirée des favoris");100      }}101      className={cn(compact ? actionIcon : action, fav && "border-accent")}102    >103      <Heart className={cn("size-4", fav && "text-accent")} fill={fav ? "currentColor" : "none"} />104      {!compact && (fav ? "Enregistrée" : "Enregistrer")}105    </button>106  );107}108109export function CompareAction({ uid, compact }: { uid: string; compact?: boolean }) {110  const on = useCompare().includes(uid);111  return (112    <button113      type="button"114      aria-pressed={on}115      aria-label={on ? "Retirer du comparateur" : "Ajouter au comparateur"}116      onClick={() => {117        const r = toggleCompare(uid);118        toast(r === "full" ? "Le comparateur contient déjà 4 propriétés" : r === "added" ? "Ajoutée au comparateur" : "Retirée du comparateur");119      }}120      className={cn(compact ? actionIcon : action, on && "border-brand text-brand")}121    >122      <Scale className="size-4" />123      {!compact && (on ? "Dans le comparateur" : "Comparer")}124    </button>125  );126}127128export function SourceButton({ p, names, className, short }: { p: Property; names?: Record<string, string>; className?: string; short?: boolean }) {129  return (130    <a href={p.url} target="_blank" rel="noopener noreferrer nofollow" className={cn(buttonClass("primary", "lg"), className)} title={`Ouvrir l'inscription sur ${sourceLabel(p.source, names)}`}>131      {short ? "Voir l'inscription" : "Voir l'inscription originale"} <ArrowUpRight className="size-4" />132    </a>133  );134}135136// --- Prix ---------------------------------------------------------------------137function PriceLine({ p, size }: { p: Property; size: "lg" | "md" | "sm" }) {138  const ok = priceUsable(p);139  const rental = isRental(p);140  const big = size === "lg" ? "text-[2.1rem] sm:text-[2.5rem]" : size === "md" ? "text-[1.7rem]" : "text-[1.05rem]";141  const alt = size === "lg" ? "text-[1.5rem]" : size === "md" ? "text-[1.15rem]" : "text-[1rem]";142  return ok ? (143    <>144      <span className={cn(big, "tracking-[-0.02em]")}>{money(p.price)}</span>145      {rental && <span className="ml-2 text-[0.9rem] font-normal tracking-normal text-ink-3">par mois</span>}146      {!rental && p.details?.price_from && <span className="ml-2 text-[0.9rem] font-normal tracking-normal text-ink-3">à partir de</span>}147    </>148  ) : (149    <span className={alt}>{size === "sm" ? "Sur demande" : "Prix sur demande"}</span>150  );151}152153function Fact({ k, v }: { k: string; v: ReactNode }) {154  return (155    <div className="min-w-0 border-t border-line pt-2.5">156      <dt className="text-[0.78rem] text-ink-3">{k}</dt>157      <dd className="num mt-0.5 break-words text-[0.96rem] font-medium text-ink">{v}</dd>158    </div>159  );160}161162function KeyFacts({ p }: { p: Property }) {163  const items: [string, string][] = [];164  const type = typeOf(p);165  const area = livingArea(p);166  if (type) items.push(["Type de propriété", type]);167  if (p.bedrooms != null && p.bedrooms > 0) items.push([p.bedrooms > 1 ? "Chambres" : "Chambre", String(Math.round(p.bedrooms))]);168  if (p.bathrooms != null && p.bathrooms > 0) items.push([p.bathrooms > 1 ? "Salles de bain" : "Salle de bain", String(p.bathrooms)]);169  if (p.powder_rooms != null && p.powder_rooms > 0) items.push([p.powder_rooms > 1 ? "Salles d'eau" : "Salle d'eau", String(p.powder_rooms)]);170  if (area) items.push(["Superficie habitable", fmtArea(area)]);171  if (p.lot_sqft != null && p.lot_sqft > 0) items.push(["Terrain", fmtLot(p.lot_sqft)]);172  if (p.year_built != null && p.year_built > 1600 && p.year_built <= new Date().getFullYear() + 3) items.push(["Année de construction", String(p.year_built)]);173  if (p.mls) items.push(["Nº Centris / MLS", p.mls]);174  items.push(["Statut", statusOf(p).label]);175  return (176    <dl className="mt-6 grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-3 xl:grid-cols-4">177      {items.map(([k, v]) => (178        <Fact key={k} k={k} v={v} />179      ))}180    </dl>181  );182}183184export function Overview({ p, names, stagger }: { p: Property; names?: Record<string, string>; stagger: boolean }) {185  const cmp = priceComparison(p);186  const st = statusOf(p);187  const fresh = st.live && !!p.first_seen && Date.now() / 1000 - p.first_seen < 3 * 86400;188  const title = titleOf(p);189  const place = placeOf(p);190  const dups = p.duplicates ?? [];191  return (192    <section id="apercu" data-section="apercu" className={cn("scroll-mt-32", stagger && "lk-stagger")}>193      <div className="flex min-h-6 flex-wrap items-center gap-x-3 gap-y-2">194        {cmp && <VerdictPill verdict={cmp.verdict} deviation={cmp.deviation} />}195        {!st.live && <span className="rounded-[6px] bg-high-soft px-2 py-1 text-[0.74rem] font-medium leading-none text-high">{st.label}</span>}196        {fresh && <span className="rounded-[6px] bg-accent-soft px-2 py-1 text-[0.74rem] font-medium leading-none text-accent-strong">Nouvelle inscription</span>}197        {p.updated_at ? <span className="text-[0.82rem] text-ink-3">Mise à jour {fmtAgo(p.updated_at)}</span> : null}198      </div>199200      <p className="num mt-4 font-semibold leading-none text-ink">201        <PriceLine p={p} size="lg" />202      </p>203      <div>204        <h1 tabIndex={-1} data-fiche-title className="mt-3 text-[1.55rem] leading-[1.15] outline-none sm:text-[1.95rem]">205          {title}206        </h1>207        {place && <p className="mt-1.5 text-[0.98rem] text-ink-2">{place}</p>}208      </div>209210      <KeyFacts p={p} />211212      <div className="mt-6 flex flex-wrap items-center gap-2">213        <SourceButton p={p} names={names} className="h-11 w-full sm:w-auto" />214        <SaveAction p={p} />215        <CompareAction uid={p.uid} />216        <button type="button" onClick={() => share(p)} className={action}>217          <Share2 className="size-4" /> Partager218        </button>219        <a href={pdfUrl(p.uid)} className={action}>220          <Download className="size-4" /> Fiche PDF221        </a>222      </div>223224      <p className="mt-5 text-[0.84rem] leading-relaxed text-ink-3">225        Inscription publiée par <span className="text-ink-2">{sourceLabel(p.source, names)}</span>226        {dups.length > 0 && <>, aussi vue sur {Array.from(new Set(dups.map((d) => sourceLabel(d.source, names)))).join(", ")}</>}. Immo-Ka ne prend aucune commission.227      </p>228    </section>229  );230}231232// --- Le vrai prix -----------------------------------------------------------------233const VERDICT_TITLE: Record<PriceComparison["verdict"], string> = {234  sous: "Le prix demandé est sous la valeur estimée",235  marche: "Le prix demandé est près de la valeur estimée",236  sur: "Le prix demandé dépasse la valeur estimée",237};238const VERDICT_COLOR: Record<PriceComparison["verdict"], string> = { sous: "var(--good)", marche: "var(--fair)", sur: "var(--high)" };239const CONFIDENCE: Record<string, string> = { A: "Confiance élevée", B: "Bonne confiance", C: "Confiance moyenne", D: "Estimation indicative" };240241/** Jauge : la fourchette estimée, l'estimation, et le prix demandé qui vient s'y poser. */242function TruePriceGauge({ price, cmp }: { price: number; cmp: PriceComparison }) {243  const low = cmp.low ?? cmp.value * 0.9;244  const high = cmp.high ?? cmp.value * 1.1;245  const min = Math.min(low, price) - (high - low) * 0.18;246  const max = Math.max(high, price) + (high - low) * 0.18;247  const pos = (x: number) => Math.min(100, Math.max(0, ((x - min) / (max - min)) * 100));248  const [ref, seen] = useSeenOnce<HTMLDivElement>();249  const at = pos(seen ? price : cmp.value);250  const color = VERDICT_COLOR[cmp.verdict];251  const settle = "transition-[left,transform] duration-700 ease-[cubic-bezier(0.3,1.45,0.5,1)]";252  // l'étiquette reste dans le cadre aux extrémités253  const shift = at < 16 ? "translate-x-0" : at > 84 ? "-translate-x-full" : "-translate-x-1/2";254  return (255    <div256      ref={ref}257      role="img"258      aria-label={`Prix demandé ${money(price)} ; valeur estimée ${money(cmp.value)}${cmp.low != null ? `, fourchette de ${money(cmp.low)} à ${money(cmp.high)}` : ""}`}259      className="relative pb-9 pt-9"260    >261      <div className={cn("num absolute top-0 whitespace-nowrap text-[0.78rem] font-medium", settle, shift)} style={{ left: `${at}%`, color }}>262        Prix demandé · {money(price)}263      </div>264      <div className="relative h-1.5 rounded-full bg-surface-3">265        {cmp.low != null && (266          <div267            className="absolute inset-y-0 origin-left rounded-full bg-ink-3/40 transition-transform duration-500 ease-[cubic-bezier(0.2,0.7,0.2,1)]"268            style={{ left: `${pos(low)}%`, right: `${100 - pos(high)}%`, transform: seen ? "none" : "scaleX(0)" }}269          />270        )}271        <div className="absolute -top-1.5 h-[18px] w-px bg-ink" style={{ left: `${pos(cmp.value)}%` }} />272        <div className={cn("absolute -top-[5px] size-4 -translate-x-1/2 rounded-full border-2 border-surface", settle)} style={{ left: `${at}%`, background: color }} />273      </div>274      {cmp.low != null && (275        <div className="num absolute bottom-3.5 -translate-x-1/2 text-[0.7rem] text-ink-3 max-sm:hidden" style={{ left: `${pos(low)}%` }}>276          {money(low)}277        </div>278      )}279      <div className="num absolute bottom-0 -translate-x-1/2 whitespace-nowrap text-[0.72rem] text-ink-2 sm:bottom-3.5" style={{ left: `${Math.min(86, Math.max(14, pos(cmp.value)))}%` }}>280        Estimation · {money(cmp.value)}281      </div>282      {cmp.high != null && (283        <div className="num absolute bottom-3.5 -translate-x-1/2 text-[0.7rem] text-ink-3 max-sm:hidden" style={{ left: `${pos(high)}%` }}>284          {money(high)}285        </div>286      )}287    </div>288  );289}290291function PriceHistory({ p }: { p: Property }) {292  const hist = (p.price_history ?? []).filter((h): h is { ts: number; price: number } => h.price != null && h.price > 0).sort((a, b) => a.ts - b.ts);293  if (hist.length < 2) return null;294  const W = 600;295  const H = 96;296  const min = Math.min(...hist.map((h) => h.price));297  const max = Math.max(...hist.map((h) => h.price));298  const t0 = hist[0]!.ts;299  const t1 = Math.max(hist[hist.length - 1]!.ts, t0 + 1);300  const x = (t: number) => 6 + ((t - t0) / (t1 - t0)) * (W - 12);301  const y = (v: number) => (max === min ? H / 2 : 10 + (1 - (v - min) / (max - min)) * (H - 20));302  // prix demandé : il change par paliers303  let d = `M${x(hist[0]!.ts)} ${y(hist[0]!.price)}`;304  for (let i = 1; i < hist.length; i++) d += ` H${x(hist[i]!.ts)} V${y(hist[i]!.price)}`;305  const first = hist[0]!;306  const last = hist[hist.length - 1]!;307  const delta = (last.price - first.price) / first.price;308  return (309    <div className="mt-6 border-t border-line pt-5">310      <div className="flex flex-wrap items-baseline justify-between gap-2">311        <h3 className="text-[1.08rem]">Historique du prix demandé</h3>312        {delta !== 0 && (313          <span className={cn("num text-[0.86rem] font-medium", delta < 0 ? "text-good" : "text-high")}>314            {delta < 0 ? "−" : "+"}315            {pct0(delta)} depuis la première observation316          </span>317        )}318      </div>319      <DrawOnView as="figure" className="mt-3" role="img" label={`Le prix demandé est passé de ${money(first.price)} à ${money(last.price)}`}>320        <svg viewBox={`0 0 ${W} ${H}`} className="block h-24 w-full" preserveAspectRatio="none" aria-hidden>321          <line x1="0" x2={W} y1={H - 1} y2={H - 1} stroke="var(--line)" vectorEffect="non-scaling-stroke" />322          <path d={d} fill="none" stroke="var(--ink-2)" strokeWidth="1.75" pathLength={1} className="lk-draw-line" style={{ ["--len" as string]: 1 }} />323        </svg>324      </DrawOnView>325      <ul className="mt-2">326        {[...hist].reverse().slice(0, 6).map((h, i, arr) => {327          const prev = arr[i + 1];328          return (329            <li key={h.ts} className="flex items-baseline justify-between gap-3 border-t border-line py-2 text-[0.9rem] first:border-0">330              <span className="text-ink-3">{fmtDay(h.ts)}</span>331              <span className="num text-right text-ink">332                {prev ? (333                  <>334                    <span className="text-ink-3">{h.price < prev.price ? "Baisse" : "Hausse"} à </span>335                    <span className="font-medium">{money(h.price)}</span>336                  </>337                ) : (338                  <>339                    <span className="text-ink-3">Premier prix observé : </span>340                    <span className="font-medium">{money(h.price)}</span>341                  </>342                )}343              </span>344            </li>345          );346        })}347      </ul>348    </div>349  );350}351352export function hasPricePanel(p: Property) {353  return priceUsable(p) && !isRental(p);354}355356/** « Le vrai prix » : l'estimation, l'écart, la fourchette, ce qu'elle vaut et ce qu'elle ignore. */357export function TruePricePanel({ p }: { p: Property }) {358  if (!hasPricePanel(p)) return null;359  const price = p.price!;360  const cmp = priceComparison(p);361  const vp = p.vraiprix && p.vraiprix.value != null && p.vraiprix.value > 0 ? p.vraiprix : null;362  const ev = municipalValueOf(p);363  const area = livingArea(p);364  const days = daysOnline(p);365  const evDev = ev ? (price - ev.total) / ev.total : null;366  const diff = cmp ? Math.abs(price - cmp.value) : 0;367  return (368    <section id="prix" data-section="prix" className="scroll-mt-32">369      <Panel title="Le vrai prix" aside={cmp ? <VerdictPill verdict={cmp.verdict} deviation={cmp.deviation} size="md" /> : undefined}>370        {cmp ? (371          <>372            <p className="max-w-2xl text-[1rem] leading-relaxed text-ink">373              {VERDICT_TITLE[cmp.verdict]}374              {cmp.verdict === "marche" ? (375                <> : l'écart est de {pct0(cmp.deviation)}.</>376              ) : (377                <>378                  {" "}379                  de <span className="num font-semibold">{money(diff)}</span>, soit {pct0(cmp.deviation)}.380                </>381              )}382            </p>383            <TruePriceGauge price={price} cmp={cmp} />384            <div className="mt-2 grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4">385              <Tile value={money(price)} label="Prix demandé" />386              <Tile value={money(cmp.value)} label="Valeur estimée" />387              {cmp.low != null && <Tile value={<span className="whitespace-nowrap text-[0.98rem]">{`${Math.round(cmp.low / 1000)} k à ${Math.round(cmp.high! / 1000)} k$`}</span>} label="Fourchette estimée" />}388              {area && <Tile value={`${fmtInt(Math.round(price / area))}${nbsp}$`} label="Par pied carré habitable" />}389            </div>390            <p className="mt-5 max-w-2xl text-[0.9rem] leading-relaxed text-ink-2">391              {cmp.confidence && CONFIDENCE[cmp.confidence] ? (392                <>393                  <b className="font-semibold text-ink">{CONFIDENCE[cmp.confidence]}</b>394                  {cmp.confidencePct != null ? ` (${Math.round(cmp.confidencePct)} %)` : ""}.{" "}395                </>396              ) : cmp.spread != null ? (397                <>398                  Le modèle ne publie pas d'indice de confiance pour cette propriété ; la largeur de la fourchette, environ ± {pct0(cmp.spread)}, donne la mesure de son incertitude.{" "}399                </>400              ) : null}401              L'estimation vient d'un modèle statistique fondé sur les ventes comparables et le rôle d'évaluation. Elle ne voit ni l'état du bâtiment, ni les rénovations, ni la vue : c'est un repère, pas une évaluation agréée.402            </p>403          </>404        ) : vp ? (405          <p className="max-w-2xl text-[0.94rem] leading-relaxed text-ink-2">406            Une estimation existe pour cette adresse (<span className="num">{money(vp.value)}</span>), mais elle est trop éloignée du prix demandé pour être comparée honnêtement. C'est fréquent pour un terrain, un immeuble commercial, un407            domaine ou une propriété très rénovée : le modèle ne décrit sans doute pas le même bien.408          </p>409        ) : (410          <p className="max-w-2xl text-[0.94rem] leading-relaxed text-ink-2">411            Aucune estimation de valeur n'est disponible pour cette inscription : l'adresse n'a pas pu être appariée au rôle d'évaluation, ou le type de bien n'est pas couvert. Le prix demandé n'est donc pas comparé.412          </p>413        )}414415        {!cmp && (area || (days != null && days > 0)) && (416          <div className="mt-5 grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4">417            <Tile value={money(price)} label="Prix demandé" />418            {area && <Tile value={`${fmtInt(Math.round(price / area))}${nbsp}$`} label="Par pied carré habitable" />}419            {days != null && days > 0 && <Tile value={`${days} j`} label="En ligne (observé)" />}420          </div>421        )}422423        {ev && (424          <div className="mt-6 border-t border-line pt-5">425            <h3 className="text-[1.08rem]">Évaluation municipale{ev.annee ? ` ${ev.annee}` : ""}</h3>426            <div className="mt-3 grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4">427              <Tile value={money(ev.total)} label="Valeur au rôle" />428              {ev.terrain != null && <Tile value={money(ev.terrain)} label="Terrain" />}429              {ev.batiment != null && <Tile value={money(ev.batiment)} label="Bâtiment" />}430            </div>431            {evDev != null && Math.abs(evDev) <= 3 && (432              <p className="mt-3 max-w-2xl text-[0.86rem] leading-relaxed text-ink-3">433                Le prix demandé est {pct0(evDev)} {evDev >= 0 ? "au-dessus de" : "sous"} l'évaluation municipale. Le rôle reflète la valeur à une date de référence passée, pas le marché d'aujourd'hui434                {ev.origine === "role" ? " ; cette valeur vient du rôle apparié à l'adresse, non de la source" : ""}.435              </p>436            )}437          </div>438        )}439440        <PriceHistory p={p} />441442        <div className="mt-5 border-t border-line">443          <Disclosure title="Comment ce verdict est établi">444            <p>445              Le verdict compare le prix demandé à la valeur estimée : à moins de 5{nbsp}% d'écart, le prix est jugé juste ; en dessous, c'est un bon prix ; au-dessus, il est élevé. Au-delà de 60{nbsp}% d'écart, aucune comparaison n'est446              affichée. L'historique et le nombre de jours en ligne sont ceux observés par Immo-Ka depuis sa première synchronisation, pas la date d'inscription officielle.447            </p>448            {vp?.url && (449              <a href={vp.url} target="_blank" rel="noopener noreferrer" className="mt-2 inline-flex min-h-11 items-center gap-1 font-medium text-brand hover:underline">450                Analyse détaillée de l'estimation <ArrowUpRight className="size-3.5" />451              </a>452            )}453          </Disclosure>454        </div>455      </Panel>456    </section>457  );458}459460// --- Résumé collant et barre mobile -------------------------------------------------461function PaymentLine({ f }: { f: Finance }) {462  if (!f.enabled || f.monthly == null) return null;463  return (464    <a href="#financement" onClick={(e) => { e.preventDefault(); document.getElementById("financement")?.scrollIntoView({ behavior: "smooth", block: "start" }); }} className="group mt-4 block border-y border-line py-3">465      <span className="flex items-baseline justify-between gap-3">466        <span className="text-[0.86rem] text-ink-3">Versement estimé</span>467        <span className="num text-[1.02rem] font-semibold text-ink">468          <Ticker value={Math.round(f.monthly)} format={money} /> <span className="text-[0.8rem] font-normal text-ink-3">/ mois</span>469        </span>470      </span>471      <span className="num mt-1 block text-[0.78rem] leading-relaxed text-ink-3">472        {Math.round(f.downPct)}{nbsp}% de mise de fonds, {f.rate != null ? f.rate.toFixed(2).replace(".", ",") : "—"}{nbsp}% sur {f.years} ans · <span className="font-medium text-brand group-hover:underline">Ajuster</span>473      </span>474    </a>475  );476}477478/** Résumé collant (grand écran) : prix, versement estimé, action principale. */479export function StickySummary({ p, f, names }: { p: Property; f: Finance; names?: Record<string, string> }) {480  const cmp = priceComparison(p);481  return (482    <div className="rounded-xl border border-line bg-surface p-5">483      <div className="flex items-start justify-between gap-3">484        <p className="num font-semibold leading-none">485          <PriceLine p={p} size="md" />486        </p>487        {cmp && <VerdictPill verdict={cmp.verdict} deviation={cmp.deviation} />}488      </div>489      <p className="mt-2 line-clamp-2 text-[0.88rem] text-ink-3">{[titleOf(p), placeOf(p)].filter(Boolean).join(" · ")}</p>490      {specLine(p) && <p className="num mt-1 text-[0.84rem] text-ink-2">{specLine(p)}</p>}491      <PaymentLine f={f} />492      <SourceButton p={p} names={names} className="mt-5 w-full" />493      <p className="mt-3 text-[0.78rem] leading-relaxed text-ink-3">Vous serez dirigé vers {sourceLabel(p.source, names)}, qui publie cette inscription.</p>494      <div className="mt-4 flex gap-2 border-t border-line pt-4">495        <SaveAction p={p} />496        <CompareAction uid={p.uid} compact />497        <button type="button" onClick={() => share(p)} aria-label="Partager cette fiche" className={actionIcon}>498          <Share2 className="size-4" />499        </button>500        <a href={pdfUrl(p.uid)} aria-label="Télécharger la fiche PDF" className={actionIcon}>501          <Download className="size-4" />502        </a>503      </div>504    </div>505  );506}507508/** Barre d'action mobile, posée au-dessus de la barre d'onglets. */509export function MobileCta({ p, f }: { p: Property; f: Finance }) {510  return (511    <div className="lk-bar-in fixed inset-x-0 bottom-[calc(3.5rem+env(safe-area-inset-bottom))] z-40 border-t border-line bg-bg lg:hidden">512      <div className="mx-auto flex max-w-xl items-center gap-2 px-4 py-2">513        <div className="min-w-0 flex-1">514          <p className="num truncate font-semibold leading-tight">515            <PriceLine p={p} size="sm" />516          </p>517          <p className="num truncate text-[0.76rem] text-ink-3">518            {f.enabled && f.monthly != null ? <>≈ {money(f.monthly)} / mois</> : [typeOf(p), placeOf(p)].filter(Boolean).join(" · ")}519          </p>520        </div>521        <span className="max-[359px]:hidden">522          <SaveAction p={p} compact />523        </span>524        <SourceButton p={p} short className="h-11 shrink-0 px-3.5 text-[0.88rem]" />525      </div>526    </div>527  );528}529
Files main
Menu

Theme