Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Vrai-Prix iOS9// File : VraiPrix/Design/Rows.swift10// Description : lignes de liste — vente publiée, propriété mémorisée,11// annonce à vendre avec sa jauge ; icônes de l'évaluation12// (brand/icons) ; conversions vers une propriété mémorisée.13// Module : VraiPrix14// Repository : https://git.spboucher.ai/vrai-prix-ios-v315// Project Website : https://www.vrai-prix.com16// Created : 2026-11-2617// Last Modified : 2026-11-2818//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author : Simon-Pierre Boucher24// Position : Professor of Finance25// Institution : Université du Québec en Outaouais (UQO)26// Department : Département des sciences administratives27// Organization : SP Boucher28//29// Website : https://spboucher.ai30// Git : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General : info@spboucher.ai37// Professional : contact@spboucher.ai38// Direct : simon@spboucher.ai39// Research : research@spboucher.ai40// Development : dev@spboucher.ai41// Support : support@spboucher.ai42// Security/Admin : admin@spboucher.ai43// Notifications : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification : Public70// Distribution : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License : None specified (no license file in this repository)84// Maintainer : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import SwiftUI9293/// Icônes d'interface de l'évaluation (grille 24, onglets vifs) du système de marque.94enum BrandIcon: String {95 case estimation, aplomb, venteConclue = "vente-conclue", roleEvaluation = "role-evaluation", comparables, ecart, indice96 case municipalite, methodeCout = "methode-cout", fourchette, terrain, batiment9798 var image: Image { Image("ic-" + rawValue).renderingMode(.template) }99}100101struct BrandIconView: View {102 let icon: BrandIcon103 var size: CGFloat = 24104 var color: Color = Theme.ink105 var body: some View {106 icon.image.resizable().scaledToFit().frame(width: size, height: size).foregroundStyle(color).accessibilityHidden(true)107 }108}109110/// Vente publiée : montant, adresse, lieu et type, date, écart avec le rôle.111struct SaleRow: View {112 let sale: Sale113 var showCity = true114 @Environment(\.dynamicTypeSize) private var typeSize115116 var body: some View {117 VStack(alignment: .leading, spacing: 4) {118 if typeSize.isAccessibilitySize {119 Text(Fmt.money(sale.amount)).font(.body.weight(.semibold)).num().foregroundStyle(Theme.ink)120 Text(Fmt.day(sale.date, short: true)).font(.footnote).num().foregroundStyle(Theme.ink3)121 } else {122 HStack(alignment: .firstTextBaseline) {123 Text(Fmt.money(sale.amount)).font(.body.weight(.semibold)).num().foregroundStyle(Theme.ink)124 Spacer(minLength: 8)125 Text(Fmt.day(sale.date, short: true)).font(.footnote).num().foregroundStyle(Theme.ink3)126 }127 }128 Text(sale.title).font(.subheadline).foregroundStyle(Theme.ink).lineLimit(2)129 Text(detail).font(.footnote).num().foregroundStyle(Theme.ink3).lineLimit(2)130 }131 .frame(maxWidth: .infinity, alignment: .leading)132 .padding(.vertical, 11)133 .contentShape(Rectangle())134 .accessibilityElement(children: .ignore)135 .accessibilityLabel("Vendue \(Fmt.money(sale.amount)) le \(Fmt.day(sale.date)). \(sale.title). \(detail)")136 }137138 private var detail: String {139 var p: [String] = []140 if showCity, let c = sale.city { p.append(c) }141 p.append(PropType.label(sale.unitGenre ?? sale.propertyType))142 if let y = sale.yearBuilt, y > 1700 { p.append(String(y)) }143 // prix vendu lu contre la valeur de la fiche (vente rattachée à son unité), sinon la raison144 if let r = sale.reading { p.append("\(Fmt.pct(r.gapPct)) par rapport à la valeur estimée") }145 else if let n = sale.unattachedNote { p.append(n) }146 return p.joined(separator: " · ")147 }148}149150/// Propriété mémorisée (favori, récent) : titre, lieu, valeur estimée.151struct SavedRow: View {152 let item: SavedProperty153154 @Environment(\.dynamicTypeSize) private var typeSize155156 var body: some View {157 let layout = typeSize.isAccessibilitySize ? AnyLayout(VStackLayout(alignment: .leading, spacing: 6)) : AnyLayout(HStackLayout(alignment: .top, spacing: 12))158 layout {159 if item.kind == .listing {160 RemoteImage(source: item.image, maxPixel: 240)161 .frame(width: 64, height: 48)162 .clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))163 }164 VStack(alignment: .leading, spacing: 3) {165 Text(item.title).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink).lineLimit(2)166 Text(item.subtitle).font(.footnote).foregroundStyle(Theme.ink3).lineLimit(typeSize.isAccessibilitySize ? 2 : 1)167 if let v = item.valueBlock {168 // mémorisée sous l'API v3 : la position rendue par le moteur, ou rien169 if v.isFirm, item.price != nil, item.priceLabel != nil, item.position != nil {170 PositionPlate(position: item.position, gapPct: item.ecartPct, size: .compact)171 }172 } else if let r = item.reading, let l = item.priceLabel {173 Text("\(l) \(Fmt.money(item.price)) · \(Fmt.pct(r.gapPct))").font(.footnote).num().foregroundStyle(Theme.color(for: r.verdict))174 }175 }176 if !typeSize.isAccessibilitySize { Spacer(minLength: 8) }177 if let v = item.valueBlock {178 ValueView(value: v, size: .line)179 } else {180 VStack(alignment: typeSize.isAccessibilitySize ? .leading : .trailing, spacing: 2) {181 Text(Fmt.money(item.value)).font(.subheadline.weight(.semibold)).num().foregroundStyle(Theme.ink)182 Text("valeur estimée").font(.caption2).foregroundStyle(Theme.ink3)183 }184 }185 }186 .frame(maxWidth: .infinity, alignment: .leading)187 .padding(.vertical, 11)188 .contentShape(Rectangle())189 .accessibilityElement(children: .combine)190 }191}192193/// Annonce à vendre : photo, prix demandé, adresse, jauge miniature et verdict.194struct ListingRow: View {195 let listing: ListingSummary196197 var body: some View {198 HStack(alignment: .top, spacing: 12) {199 RemoteImage(source: listing.image, maxPixel: 360)200 .frame(width: 104, height: 78)201 .clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))202 VStack(alignment: .leading, spacing: 4) {203 Text(Fmt.money(listing.price)).font(.body.weight(.semibold)).num().foregroundStyle(Theme.ink)204 Text(listing.title).font(.subheadline).foregroundStyle(Theme.ink).lineLimit(1)205 Text([listing.city, listing.facts].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: " · "))206 .font(.footnote).foregroundStyle(Theme.ink3).lineLimit(1)207 if listing.hasEstimate, let est = listing.est, let low = listing.low, let high = listing.high, let r = listing.reading {208 MiniGauge(scale: GaugeScale(value: est, low: low, high: high, price: listing.price))209 .padding(.top, 2)210 // sur une ligne si la largeur le permet, sinon l'estimation passe dessous (jamais de libellé tronqué)211 ViewThatFits(in: .horizontal) {212 HStack(spacing: 8) {213 VerdictTag(verdict: r.verdict, gapPct: r.gapPct).fixedSize()214 Text("est. " + Fmt.compact(est)).font(.caption).num().foregroundStyle(Theme.ink3).lineLimit(1).fixedSize()215 }216 VStack(alignment: .leading, spacing: 3) {217 VerdictTag(verdict: r.verdict, gapPct: r.gapPct)218 Text("valeur estimée " + Fmt.compact(est)).font(.caption).num().foregroundStyle(Theme.ink3).lineLimit(1)219 }220 }221 } else {222 Text(listing.noEstimateNote).font(.caption).foregroundStyle(Theme.ink3).lineLimit(2)223 }224 }225 .frame(maxWidth: .infinity, alignment: .leading)226 }227 .padding(.vertical, 12)228 .contentShape(Rectangle())229 .accessibilityElement(children: .ignore)230 .accessibilityLabel(a11y)231 }232233 private var a11y: String {234 var s = "\(listing.title), \(listing.city ?? ""). Prix demandé \(Fmt.money(listing.price))."235 if listing.hasEstimate, let r = listing.reading { s += " Valeur estimée \(Fmt.money(listing.est)). \(r.verdict.label), \(Fmt.pct(r.gapPct))." } else { s += " " + listing.noEstimateNote + "." }236 return s237 }238}239240/// Ligne de navigation sobre : icône de l'évaluation, titre, précision, chevron.241struct NavRow: View {242 let icon: BrandIcon243 let title: String244 var detail: String?245 var divider = true246 let action: () -> Void247248 var body: some View {249 Button(action: action) {250 VStack(spacing: 0) {251 HStack(spacing: 14) {252 BrandIconView(icon: icon, size: 24, color: Theme.ink)253 VStack(alignment: .leading, spacing: 2) {254 Text(title).font(.body).foregroundStyle(Theme.ink).multilineTextAlignment(.leading)255 if let detail { Text(detail).font(.footnote).num().foregroundStyle(Theme.ink3).multilineTextAlignment(.leading) }256 }257 Spacer(minLength: 8)258 Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(Theme.ink3)259 }260 .padding(.vertical, 13)261 .frame(minHeight: 52)262 if divider { Hairline() }263 }264 .contentShape(Rectangle())265 }266 .buttonStyle(.plain)267 }268}269270// MARK: - Conversions271272extension SavedProperty {273 init?(unit d: UnitDetail) {274 guard let u = d.unit else { return nil }275 // le prix lu : celui de l'inscription à vendre de l'unité, sinon sa dernière vente276 let recent = d.sales.first { ($0.amount ?? 0) > 0 }277 let server = d.inscription.flatMap { Reading(verdict: $0.verdict, ecartPct: $0.ecartPct, dansFourchette: $0.dansFourchette) }278 ?? (d.inscription == nil ? recent.flatMap { Reading(verdict: $0.verdict, ecartPct: $0.ecartPct, dansFourchette: $0.dansFourchette) } : nil)279 self.init(kind: .unit, ref: u.id, title: u.title,280 subtitle: [u.municipalite, u.typeShort].compactMap { $0 }.joined(separator: " · "),281 value: d.result.estimate, low: d.result.low, high: d.result.high, price: d.inscription?.prix ?? recent?.amount,282 priceLabel: d.inscription != nil ? "Demandé" : (recent == nil ? nil : "Vendue"), confidence: d.result.confidenceLevel, year: u.anneeConstruction,283 areaM2: u.aireEtagesM2, landM2: u.superficieTerrainM2, roll: u.valeurRole, image: nil,284 verdictKey: server?.verdict.rawValue, ecartPct: server?.gapPct, dansFourchette: server?.inRange)285 }286287 init(listing d: ListingDetail) {288 let l = d.listing289 self.init(kind: .listing, ref: l.uid, title: Fmt.address(l.address),290 subtitle: [l.city, l.propertyType].compactMap { $0 }.joined(separator: " · "),291 value: d.hasEstimate ? d.eval?.est : nil, low: d.hasEstimate ? d.eval?.low : nil, high: d.hasEstimate ? d.eval?.high : nil,292 price: l.price, priceLabel: "Demandé", confidence: d.eval?.confidence, year: l.yearBuilt,293 areaM2: l.areaSqft.map { $0 / 10.7639 }, landM2: l.lotSqft.map { $0 / 10.7639 }, roll: d.eval?.valeurRole, image: d.images.first,294 verdictKey: d.reading?.verdict.rawValue, ecartPct: d.reading?.gapPct, dansFourchette: d.reading?.inRange)295 }296}297