SPB Git

Repository Public

ui.tsx 8.5 KB 149 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/components/avendre/cost/ui.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 — petits composants partagés de l'analyse IA du bâtiment (badges de couche, sections, tableau RCN, viewer JSON).43"use client";44import { useState } from "react";45import type { Layer } from "@/lib/cost/types";46import type { CostEstimate } from "@/lib/cost/types";47import { money, num, pct } from "../fmt";4849export function Sect({ num: n, kicker, title, id }: { num: string; kicker: string; title: string; id?: string }) {50  return (51    <header className="sec" id={id}>52      <span className="sec-num">{n} — {kicker}</span>53      <h2 className="vp-display mt-2 text-[clamp(20px,3vw,28px)] font-bold uppercase leading-[1.05] tracking-[-0.025em]">{title}</h2>54    </header>55  );56}5758/** §208 — les quatre couches, toujours nommées : OBSERVÉ · INFÉRÉ PAR IA · CALCULÉ · PRIX SOURCÉ (+ hypothèse). */59export function LayerBadge({ layer, fr }: { layer: Layer; fr: boolean }) {60  const map: Record<Layer, { fr: string; en: string; cls: string }> = {61    observed: { fr: "Observé", en: "Observed", cls: "border-ink bg-ink text-paper" },62    ai_inferred: { fr: "Inféré par IA", en: "AI-inferred", cls: "border-[var(--accent)] text-[var(--accent-deep)]" },63    computed: { fr: "Calculé", en: "Computed", cls: "border-[var(--line-strong)] text-ink" },64    sourced_price: { fr: "Prix sourcé", en: "Sourced price", cls: "border-[var(--green)] text-[var(--green-deep)]" },65    assumption: { fr: "Hypothèse", en: "Assumption", cls: "border-[var(--amber)] bg-[var(--amber-soft)] text-[#8a5a12]" },66  };67  const m = map[layer];68  return <span className={`vp-mono inline-block border px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-[0.08em] ${m.cls}`}>{fr ? m.fr : m.en}</span>;69}7071export function layerOf(source: string | null | undefined): Layer {72  switch (source) {73    case "MAMH": case "listing": case "cadastral": case "user": return "observed";74    case "AI": case "photo": case "ai_estimated": return "ai_inferred";75    case "derived": return "computed";76    case "assumed": case "unknown": return "assumption";77    default: return "computed";78  }79}8081export function ConfBar({ value, fr }: { value: number; fr: boolean }) {82  const p = Math.round(value <= 1 ? value * 100 : value);83  const tone = p >= 80 ? "bg-ink" : p >= 60 ? "bg-[var(--accent)]" : p >= 40 ? "bg-[var(--amber)]" : "bg-[var(--danger)]";84  return (85    <span className="inline-flex items-center gap-1.5" title={fr ? `Confiance ${p} %` : `Confidence ${p}%`}>86      <span className="inline-block h-[5px] w-10 bg-[var(--line)]"><span className={`block h-full ${tone}`} style={{ width: `${p}%` }} /></span>87      <span className="vp-mono text-[10px] text-ink-3">{p} %</span>88    </span>89  );90}9192export function Stat({ k, v, sub, big }: { k: string; v: string; sub?: string; big?: boolean }) {93  return (94    <div className="kv-cell">95      <p className="k">{k}</p>96      <p className={`v ${big ? "text-[22px]" : ""}`}>{v}</p>97      {sub ? <p className="vp-mono mt-0.5 text-[10px] uppercase tracking-[0.05em] text-ink-3">{sub}</p> : null}98    </div>99  );100}101102/** Tableau RCN par catégorie → indirects → RCN → dépréciation → terrain → indication (§206). */103export function CostTable({ e, fr }: { e: CostEstimate; fr: boolean }) {104  const lang = fr ? "fr" : "en";105  const row = (label: string, v: number | null, opts: { bold?: boolean; neg?: boolean; sep?: boolean; layer?: Layer } = {}) => (106    <tr key={label} className={`${opts.bold ? "font-bold" : ""} ${opts.sep ? "border-t-2 border-ink" : ""}`}>107      <td>{label}{opts.layer ? <span className="ml-2"><LayerBadge layer={opts.layer} fr={fr} /></span> : null}</td>108      <td className={`vp-mono text-right ${opts.neg ? "text-[var(--danger)]" : ""}`}>{v == null ? "—" : `${opts.neg && v > 0 ? "−" : ""}${money(Math.abs(v), lang)}`}</td>109    </tr>110  );111  return (112    <div className="src-wrap">113      <table className="src-table">114        <thead><tr><th>{fr ? "Coût de remplacement à neuf" : "Replacement cost new"}</th><th className="text-right">$</th></tr></thead>115        <tbody>116          {e.categories.map((c) => row(fr ? c.labelFr : c.labelEn, c.adjusted, { layer: "computed" }))}117          {row(fr ? "Coûts directs" : "Direct costs", e.directCost, { bold: true, sep: true })}118          {row(fr ? "Coûts indirects" : "Indirect costs", e.indirectCost, { layer: "assumption" })}119          {row(fr ? `Frais généraux (${num(e.input.params.overheadPct, lang, 1)} %)` : `Overhead (${num(e.input.params.overheadPct, lang, 1)}%)`, e.contractorOverhead, { layer: "assumption" })}120          {row(fr ? `Profit (${num(e.input.params.profitPct, lang, 1)} %)` : `Profit (${num(e.input.params.profitPct, lang, 1)}%)`, e.contractorProfit, { layer: "assumption" })}121          {row(fr ? `Contingence (${num(e.input.params.contingencyPct, lang, 1)} %)` : `Contingency (${num(e.input.params.contingencyPct, lang, 1)}%)`, e.contingency, { layer: "assumption" })}122          {row(fr ? "COÛT DE REMPLACEMENT À NEUF (RCN)" : "REPLACEMENT COST NEW (RCN)", e.replacementCostNew, { bold: true, sep: true })}123          {row(fr ? "Détérioration physique" : "Physical deterioration", e.depreciation.physical, { neg: true, layer: "computed" })}124          {row(fr ? "Désuétude fonctionnelle" : "Functional obsolescence", e.depreciation.functional, { neg: true })}125          {row(fr ? "Désuétude externe" : "External obsolescence", e.depreciation.external, { neg: true })}126          {row(fr ? "Valeur dépréciée du bâtiment" : "Depreciated building value", e.depreciation.depreciatedImprovementValue, { bold: true, sep: true })}127          {row(fr ? "Valeur du terrain" : "Land value", e.landValue, { layer: e.input.land.source === "role" ? "observed" : e.input.land.source === "none" ? "assumption" : "observed" })}128          {row(fr ? "INDICATION PAR LE COÛT" : "COST APPROACH INDICATION", e.costApproachValue, { bold: true, sep: true })}129        </tbody>130      </table>131      <p className="vp-mono mt-2 text-[10px] uppercase tracking-[0.05em] text-ink-3">132        {fr ? `Fourchette RCN : ${money(e.range.p10, lang)} – ${money(e.range.p90, lang)} (P10-P90) · ${num(e.perSqft, lang, 0)} $/pi² · prix du ${e.priceDate}` : `RCN range: ${money(e.range.p10, lang)} – ${money(e.range.p90, lang)} (P10-P90) · $${num(e.perSqft, lang, 0)}/sq ft · prices as of ${e.priceDate}`}133        {e.coverage.pricingCoverage < 1 ? ` · ${fr ? "couverture des coûts" : "cost coverage"} ${pct(e.coverage.pricingCoverage * 100, lang, 0, false)}` : ""}134      </p>135    </div>136  );137}138139export function JsonViewer({ value, fr }: { value: unknown; fr: boolean }) {140  const [open, setOpen] = useState(false);141  const txt = JSON.stringify(value, null, 2);142  return (143    <div>144      <button type="button" className="btn btn-ghost" onClick={() => setOpen((o) => !o)}>{open ? (fr ? "Masquer le JSON" : "Hide JSON") : (fr ? "Voir les données techniques (JSON)" : "View technical data (JSON)")}</button>145      {open && <pre className="vp-mono mt-3 max-h-[520px] overflow-auto border border-[var(--line)] bg-surface-2 p-3 text-[10.5px] leading-snug">{txt}</pre>}146    </div>147  );148}149
Files main
Menu

Theme