SPB Git

Repository Public

HomeClient.tsx 22.9 KB 500 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/HomeClient.tsx9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-08-1312 * Last Modified    : 2026-10-2013 *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"use client";43import { useState } from "react";44import Link from "next/link";45import SearchBox from "@/components/SearchBox";46import EstimateForm from "@/components/EstimateForm";47import { locNum, MarketPulseChart } from "@/components/MetricViz";48import { useLang } from "@/components/LangContext";4950/** Indice de marché d'un grand type — série + variations (calculé côté serveur). */51export interface PulseItem {52  type: "unifamilial" | "condo" | "plex";53  series: { month: string; idx: number }[];54  pct12m: number | null;55  since2021: number | null;56}5758/** Vente réelle récente appariée à une unité d'évaluation. */59export interface RecentSaleItem {60  id: string;61  date: string;62  amount: number;63  street: string | null;64  city: string | null;65  propertyType: string | null;66  idProvinc: string | null;67  vsRolePct: number | null;68}6970const PULSE_LABELS: Record<PulseItem["type"], { fr: string; en: string }> = {71  unifamilial: { fr: "Unifamiliale", en: "Single-family" },72  condo: { fr: "Condo", en: "Condo" },73  plex: { fr: "Plex", en: "Plex" },74};75/* attribution FIXE des couleurs de série (jamais recyclée) */76const PULSE_COLORS: Record<PulseItem["type"], string> = {77  unifamilial: "var(--chart-1)",78  condo: "var(--chart-2)",79  plex: "var(--chart-3)",80};8182/** Variation signée — l'encre porte le positif, le rouge danger le négatif. */83function Pct({ v, digits = 1 }: { v: number | null; digits?: number }) {84  if (v == null) return <span className="text-ink-3">—</span>;85  return (86    <span className={v >= 0 ? "text-ink" : "text-[var(--danger)]"}>87      {v >= 0 ? "+" : "−"}88      {Math.abs(v).toFixed(digits)}&nbsp;%89    </span>90  );91}9293/** En-tête de section éditorial : filet fort, numéro mono rouge, titre display. */94function SectionHead({95  num,96  kicker,97  title,98  lede,99}: {100  num: string;101  kicker: string;102  title: string;103  lede?: string;104}) {105  return (106    <header className="sec">107      <div className="flex flex-wrap items-baseline gap-x-4 gap-y-1">108        <span className="sec-num">109          {num} — {kicker}110        </span>111      </div>112      <h2 className="vp-display mt-2 max-w-3xl text-[clamp(24px,3.6vw,36px)] font-bold uppercase leading-[1.02] tracking-[-0.03em]">113        {title}114      </h2>115      {lede && <p className="mt-3 max-w-2xl text-[14.5px] leading-relaxed text-ink-2">{lede}</p>}116    </header>117  );118}119120const PERIODS = [121  { key: "12", months: 12, fr: "12 mois", en: "12 mo" },122  { key: "24", months: 24, fr: "24 mois", en: "24 mo" },123  { key: "all", months: null as number | null, fr: "Depuis 2021", en: "Since 2021" },124] as const;125126export default function HomeClient({127  pulse,128  recent,129  salesLast30d,130}: {131  pulse: PulseItem[];132  recent: RecentSaleItem[];133  salesLast30d: number;134}) {135  const { lang, t } = useLang();136  const fr = lang === "fr";137  const [period, setPeriod] = useState<(typeof PERIODS)[number]["key"]>("24");138  const money = (v: number) =>139    new Intl.NumberFormat(fr ? "fr-CA" : "en-CA", {140      style: "currency",141      currency: "CAD",142      maximumFractionDigits: 0,143    }).format(v);144  const dateFmt = (d: string) =>145    new Date(`${d}T12:00:00`).toLocaleDateString(fr ? "fr-CA" : "en-CA", {146      day: "numeric",147      month: "short",148    });149150  const months = PERIODS.find((p) => p.key === period)?.months ?? 24;151  const chartData = pulse.map((p) => ({152    key: p.type,153    label: PULSE_LABELS[p.type][lang],154    color: PULSE_COLORS[p.type],155    series: p.series,156  }));157158  const proofs: [string, string][] = [159    ["3 747 008", fr ? "propriétés estimées" : "estimated properties"],160    ["745 119", fr ? "ventes réelles 2021-2026" : "real sales 2021-2026"],161    [locNum(salesLast30d, lang, { maxFrac: 0 }), fr ? "ventes captées / 30 jours" : "sales captured / 30 days"],162    ["1 100", fr ? "municipalités couvertes" : "municipalities covered"],163  ];164165  return (166    <div className="pb-6">167      {/* ================= HÉRO — terminal encre pleine largeur ================= */}168      <section className="bleed vp-dark">169        <div className="mx-auto max-w-6xl px-4 pb-10 pt-12 sm:px-6 sm:pb-14 sm:pt-16">170          <span className="kicker !text-[var(--accent-bright)] [&::before]:!bg-[var(--accent-bright)]">171            {fr172              ? "Terminal public de valeur immobilière — Québec"173              : "Public real-estate value terminal — Québec"}174          </span>175          <h1 className="vp-display mt-4 text-[clamp(38px,8vw,92px)] font-bold uppercase leading-[0.95] tracking-[-0.035em]">176            {fr ? (177              <>178                La <span className="outline-txt">vraie</span> valeur.179                <br />180                <span className="text-[var(--accent-bright)]">Sans boîte noire.</span>181              </>182            ) : (183              <>184                The <span className="outline-txt">true</span> value.185                <br />186                <span className="text-[var(--accent-bright)]">No black box.</span>187              </>188            )}189          </h1>190          <p className="mt-5 max-w-xl text-[15.5px] leading-relaxed text-[rgba(245,243,238,0.72)]">191            {t("sub")}192          </p>193194          {/* -------- la recherche : l'action centrale de la page -------- */}195          <div className="mt-9 max-w-3xl">196            <p className="vp-mono mb-1 text-[10.5px] font-medium uppercase tracking-[0.16em] text-[rgba(245,243,238,0.55)]">197              {fr ? "Entrez une adresse au Québec" : "Enter a Québec address"}198            </p>199            <SearchBox variant="hero" />200            <p className="vp-mono mt-2.5 text-[10px] uppercase tracking-[0.06em] text-[rgba(245,243,238,0.4)]">201              {t("dataNote")}202            </p>203          </div>204205          {/* -------- preuves de profondeur de données, intégrées -------- */}206          <div className="mt-10 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-[rgba(245,243,238,0.16)] pt-6 sm:grid-cols-4">207            {proofs.map(([num, label], i) => (208              <div key={label}>209                <p className="vp-display flex items-baseline gap-2 text-[clamp(20px,2.6vw,28px)] font-bold leading-none tracking-[-0.02em] text-[var(--paper-on-ink)]">210                  {num}211                  {i === 2 && (212                    <span213                      aria-hidden="true"214                      className="inline-block h-[7px] w-[7px] rounded-full bg-[var(--accent-bright)] [animation:pulse_2.4s_ease_infinite]"215                    />216                  )}217                </p>218                <p className="vp-mono mt-1.5 text-[9.5px] uppercase tracking-[0.12em] text-[rgba(245,243,238,0.5)]">219                  {label}220                </p>221              </div>222            ))}223          </div>224        </div>225      </section>226227      {/* ============ le principe, en une ligne (pas de boîtes) ============ */}228      <section className="border-b border-[var(--line)] py-6">229        <div className="grid gap-x-8 gap-y-4 sm:grid-cols-3">230          {(fr231            ? [232                ["01", "Cherchez l'adresse", "3,7 M d'unités d'évaluation, recherche tolérante aux fautes."],233                ["02", "Deux sources croisées", "Modèle hédonique (690 k ventes) + comparables réels ajustés en dollars."],234                ["03", "Fourchette + confiance", "P10-P90, indice A-D — le calcul montré en entier."],235              ]236            : [237                ["01", "Search the address", "3.7M assessment units, typo-tolerant search."],238                ["02", "Two sources, crossed", "Hedonic model (690k sales) + real comparables adjusted in dollars."],239                ["03", "Range + confidence", "P10-P90, A-D index — the full math, shown."],240              ]241          ).map(([num, title, body]) => (242            <div key={num} className="flex items-start gap-3">243              <span className="vp-mono pt-[3px] text-[11px] font-bold text-accent">{num}</span>244              <p className="text-[13px] leading-snug text-ink-2">245                <span className="vp-display block text-[14px] font-bold uppercase tracking-[-0.01em] text-ink">246                  {title}247                </span>248                {body}249              </p>250            </div>251          ))}252        </div>253      </section>254255      {/* ================= ATELIERS — à vendre + méthode du coût ================= */}256      <section className="mt-8 grid gap-4 lg:grid-cols-2">257        <Link href="/a-vendre" className="vp-card vp-card-hover flex flex-col border-l-4 border-l-[var(--accent)] p-5">258          <span className="kicker">{fr ? "Nouveau — maisons à vendre" : "New — homes for sale"}</span>259          <h2 className="vp-display mt-2 text-[20px] font-bold uppercase tracking-[-0.02em]">260            {fr ? "Évaluer une propriété réellement à vendre" : "Value a property actually for sale"}261          </h2>262          <p className="mt-2 flex-1 text-[13.5px] leading-relaxed text-ink-2">263            {fr264              ? "Plus de 70 000 propriétés à vendre au Québec (annonces publiques), chacune déjà mesurée par le moteur Vrai-Prix. Ouvrez une fiche, comparez la mesure au prix demandé, puis choisissez vos propres comparables et ajustez-les en dollars."265              : "Over 70,000 properties for sale in Québec (public listings), each already measured by the Vrai-Prix engine. Open a listing, compare the measure with the asking price, then pick your own comparables and adjust them in dollars."}266          </p>267          <span className="vp-mono mt-3 text-[11px] font-bold uppercase tracking-[0.08em] text-accent">268            {fr ? "Voir les propriétés à vendre" : "See properties for sale"} →269          </span>270        </Link>271        <Link href="/cout" className="vp-card vp-card-hover flex flex-col border-l-4 border-l-[var(--accent-bright)] p-5">272          <span className="kicker">{fr ? "Nouveau — méthode du coût" : "New — cost approach"}</span>273          <h2 className="vp-display mt-2 text-[20px] font-bold uppercase tracking-[-0.02em]">274            {fr ? "Combien coûterait ce bâtiment à reconstruire ?" : "What would this building cost to rebuild?"}275          </h2>276          <p className="mt-2 flex-1 text-[13.5px] leading-relaxed text-ink-2">277            {fr278              ? "Coût de remplacement à neuf décomposé par assemblages — matériaux sourcés (Canac, BMR, Patrick Morin), heures de métier aux taux APCHQ/CCQ, indices StatCan, facteurs régionaux —, puis dépréciation et valeur du terrain. Chaque hypothèse et chaque source sont visibles."279              : "Replacement cost new broken down by assemblies — sourced materials (Canac, BMR, Patrick Morin), trade hours at APCHQ/CCQ rates, StatCan indexes, regional factors —, then depreciation and land value. Every assumption and every source is visible."}280          </p>281          <span className="vp-mono mt-3 text-[11px] font-bold uppercase tracking-[0.08em] text-accent">282            {fr ? "Explorer les coûts" : "Explore costs"} →283          </span>284        </Link>285      </section>286287      {/* ================= MARCHÉ — data visualization éditoriale ================= */}288      <section className="mt-12">289        <SectionHead290          num="01"291          kicker={fr ? "Indice Vrai-Prix" : "Vrai-Prix index"}292          title={fr ? "Le pouls du marché québécois" : "The pulse of the Québec market"}293          lede={294            fr295              ? "L'indice mensuel calculé sur les ventes réelles — celui-là même qui ajuste les comparables de chaque estimation. Trois grands types, une même échelle : base 100 au début de la période."296              : "The monthly index built from real sales — the same one adjusting every estimate's comparables. Three major types, one scale: base 100 at the period start."297          }298        />299300        {/* contrôles : période (une rangée, au-dessus du graphique) */}301        <div className="mt-5 flex flex-wrap items-end justify-between gap-x-6 gap-y-2 border-b border-[var(--line)]">302          <div className="flex gap-5">303            {PERIODS.map((p) => (304              <button305                key={p.key}306                type="button"307                className="vp-tab"308                aria-pressed={period === p.key}309                onClick={() => setPeriod(p.key)}310              >311                {p[lang]}312              </button>313            ))}314          </div>315          {/* légende — l'identité ne repose jamais sur la couleur seule */}316          <div className="flex flex-wrap gap-x-4 gap-y-1 pb-2">317            {chartData.map((s) => (318              <span key={s.key} className="vp-mono flex items-center gap-1.5 text-[10px] uppercase tracking-[0.08em] text-ink-2">319                <span className="inline-block h-[2px] w-[14px]" style={{ background: s.color }} />320                {s.label}321              </span>322            ))}323          </div>324        </div>325326        <div className="mt-4">327          <MarketPulseChart data={chartData} lang={lang} months={months} />328        </div>329330        {/* lecture par type : variations en colonnes de données */}331        <div className="mt-5 grid gap-x-8 gap-y-3 border-t border-[var(--line)] pt-4 sm:grid-cols-3">332          {pulse.map((p) => (333            <div key={p.type} className="flex items-baseline justify-between gap-4 sm:block">334              <p className="vp-mono flex items-center gap-1.5 text-[10.5px] font-bold uppercase tracking-[0.08em] text-ink">335                <span className="inline-block h-[2px] w-[12px]" style={{ background: PULSE_COLORS[p.type] }} />336                {PULSE_LABELS[p.type][lang]}337              </p>338              <p className="vp-mono mt-1 flex gap-4 text-[11px] text-ink-2">339                <span>340                  12&nbsp;{fr ? "mois" : "mo"}&nbsp;341                  <b className="vp-display text-[14px]">342                    <Pct v={p.pct12m} />343                  </b>344                </span>345                <span>346                  2021→&nbsp;347                  <b className="vp-display text-[14px]">348                    <Pct v={p.since2021} digits={0} />349                  </b>350                </span>351              </p>352            </div>353          ))}354        </div>355      </section>356357      {/* ================= VENTES RÉELLES — flux prix-d'abord ================= */}358      {recent.length > 0 && (359        <section id="ventes" className="mt-14 scroll-mt-20">360          <SectionHead361            num="02"362            kicker={fr ? "Flux en continu" : "Live feed"}363            title={fr ? "Dernières ventes réelles captées" : "Latest real sales captured"}364            lede={365              fr366                ? "Transactions publiées, appariées automatiquement à leur unité d'évaluation. Chaque vente mène à l'estimation complète de la propriété."367                : "Published transactions, automatically matched to their assessment unit. Each sale leads to the property's full estimate."368            }369          />370          <div className="mt-5">371            {recent.map((s) => {372              const inner = (373                <div className="flex flex-wrap items-baseline gap-x-4 gap-y-1 sm:flex-nowrap">374                  {/* le prix d'abord — la donnée mène */}375                  <p className="vp-display w-full text-[22px] font-bold leading-none tracking-[-0.02em] sm:w-[168px] sm:shrink-0 sm:text-[20px]">376                    {money(s.amount)}377                  </p>378                  <div className="min-w-0 flex-1">379                    <p className="truncate text-[14.5px] font-semibold leading-snug">380                      {s.street}381                      {s.city ? `, ${s.city}` : ""}382                    </p>383                    <p className="vp-mono mt-0.5 text-[10.5px] uppercase tracking-[0.05em] text-ink-3">384                      {dateFmt(s.date)}385                      {s.propertyType && s.propertyType !== "indéterminé" ? ` · ${s.propertyType}` : ""}386                      {s.vsRolePct != null && Math.abs(s.vsRolePct) < 400 && (387                        <>388                          {" · "}389                          <span className={s.vsRolePct >= 0 ? "text-ink-2" : "text-[var(--danger)]"}>390                            {s.vsRolePct >= 0 ? "+" : "−"}391                            {Math.abs(s.vsRolePct).toFixed(0)} % {fr ? "vs rôle" : "vs roll"}392                          </span>393                        </>394                      )}395                    </p>396                  </div>397                  {s.idProvinc && (398                    <p className="vp-mono shrink-0 text-[10.5px] font-bold uppercase tracking-[0.08em] text-accent">399                      {fr ? "Voir l'estimation" : "See the estimate"} →400                    </p>401                  )}402                </div>403              );404              return s.idProvinc ? (405                <Link key={s.id} href={`/estimation/${encodeURIComponent(s.idProvinc)}`} className="feed-row">406                  {inner}407                </Link>408              ) : (409                <div key={s.id} className="feed-row">410                  {inner}411                </div>412              );413            })}414          </div>415          <div className="mt-5">416            <Link href="/ventes" className="btn btn-ghost">417              {fr ? "Toutes les ventes récentes — registre complet" : "All recent sales — full registry"} →418            </Link>419          </div>420        </section>421      )}422423      {/* ================= LE CALCUL, MONTRÉ — promesse centrale ================= */}424      <section className="mt-14">425        <SectionHead426          num="03"427          kicker={fr ? "Sans boîte noire" : "No black box"}428          title={fr ? "Voici exactement comment le prix est calculé" : "Here is exactly how the price is computed"}429        />430        <div className="mt-6 grid gap-10 lg:grid-cols-[1.2fr_1fr]">431          <ol className="tl">432            {(fr433              ? [434                  ["Propriété identifiée", "3,7 M d'unités d'évaluation géoréférencées (MAMH)."],435                  ["Rôle d'évaluation récupéré", "Valeurs terrain + bâtiment, six millésimes 2021-2026."],436                  ["Ventes comparables sélectionnées", "Rayon adaptatif, même famille de type, aire ±20 %."],437                  ["Caractéristiques ajustées", "Marché, superficie, âge — chaque ajustement affiché en dollars."],438                  ["Estimation calculée", "65 % modèle hédonique + 35 % comparables pondérés."],439                  ["Intervalle de confiance produit", "Fourchette P10-P90 et indice A-D, toujours affichés."],440                ]441              : [442                  ["Property identified", "3.7M georeferenced assessment units (MAMH)."],443                  ["Assessment roll retrieved", "Land + building values, six vintages 2021-2026."],444                  ["Comparable sales selected", "Adaptive radius, same type family, area ±20%."],445                  ["Characteristics adjusted", "Market, area, age — every adjustment shown in dollars."],446                  ["Estimate computed", "65% hedonic model + 35% weighted comparables."],447                  ["Confidence interval produced", "P10-P90 range and A-D index, always shown."],448                ]449            ).map(([title, body], i, arr) => (450              <li key={title} className="tl-step" data-accent={i === arr.length - 1 ? "true" : undefined}>451                <p className="vp-display flex items-baseline gap-2.5 text-[15px] font-bold uppercase tracking-[-0.01em]">452                  <span className="vp-mono text-[10.5px] font-bold text-accent">0{i + 1}</span>453                  {title}454                </p>455                <p className="mt-1 text-[13px] leading-snug text-ink-2">{body}</p>456              </li>457            ))}458          </ol>459          <div>460            {(lang === "fr"461              ? [462                  ["Le calcul, montré", "Chaque ajustement de chaque comparable est affiché en dollars. Pas de score magique."],463                  ["Fourchette honnête", "Un prix unique est un mensonge statistique. On donne P10-P90 et un indice de confiance A-D."],464                  ["Données réelles", "Rôles fonciers officiels (MAMH) et ventes publiées — locales et récentes en priorité."],465                ]466              : [467                  ["The math, shown", "Every adjustment on every comparable is displayed in dollars. No magic score."],468                  ["Honest range", "A single price is a statistical lie. We give P10-P90 and an A-D confidence index."],469                  ["Real data", "Official assessment rolls (MAMH) and published sales — local and recent first."],470                ]471            ).map(([title, body]) => (472              <div key={title} className="border-t border-[var(--line)] py-4 first:border-t-0 first:pt-0">473                <h3 className="vp-display text-[15px] font-bold uppercase tracking-[-0.01em]">{title}</h3>474                <p className="mt-1.5 text-[13px] leading-snug text-ink-2">{body}</p>475              </div>476            ))}477            <p className="vp-mono mt-2 border-t border-[var(--line)] pt-4 text-[11px] uppercase tracking-[0.06em]">478              <Link href="/methodologie" className="border-b border-accent pb-px text-accent-deep hover:text-accent">479                {fr ? "Méthodologie complète — niveau rapport technique" : "Full methodology — technical-report depth"} →480              </Link>481            </p>482          </div>483        </div>484      </section>485486      {/* ================= PLAN B — estimation sans adresse ================= */}487      <section className="mt-14">488        <SectionHead489          num="04"490          kicker={fr ? "Plan B" : "Plan B"}491          title={t("manualTitle")}492        />493        <div className="mt-6 max-w-3xl">494          <EstimateForm />495        </div>496      </section>497    </div>498  );499}500
Files main
Menu

Theme