Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Vrai-Prix iOS9// File : VraiPrix/Features/V3/CompareV3View.swift10// Description : comparateur sous l'API v3 : jusqu'à huit propriétés sur un11// axe commun (le plomb de chacune est à sa valeur, pas au12// centre), puis leurs caractéristiques côte à côte. Une13// propriété sans valeur reste dans la comparaison, sans14// montant et avec sa raison.15// Module : VraiPrix16// Repository : https://git.spboucher.ai/vrai-prix-ios-v317// Project Website : https://www.vrai-prix.com18// Created : 2026-11-2819// Last Modified : 2026-11-2820//21// =============================================================================22// AUTHOR & PROFESSIONAL AFFILIATION23// =============================================================================24//25// Author : Simon-Pierre Boucher26// Position : Professor of Finance27// Institution : Université du Québec en Outaouais (UQO)28// Department : Département des sciences administratives29// Organization : SP Boucher30//31// Website : https://spboucher.ai32// Git : https://git.spboucher.ai33//34// =============================================================================35// OFFICIAL CONTACT DIRECTORY36// =============================================================================37//38// General : info@spboucher.ai39// Professional : contact@spboucher.ai40// Direct : simon@spboucher.ai41// Research : research@spboucher.ai42// Development : dev@spboucher.ai43// Support : support@spboucher.ai44// Security/Admin : admin@spboucher.ai45// Notifications : notifications@spboucher.ai46//47// Preferred Contact: support@spboucher.ai48//49// =============================================================================50// COPYRIGHT & INTELLECTUAL PROPERTY51// =============================================================================52//53// Copyright (c) 202654// Simon-Pierre Boucher55//56// All rights reserved where applicable.57//58// This file is governed by the applicable project license,59// copyright notices, institutional agreements and relevant law.60//61// Unless expressly authorized by the applicable license or62// rights holder, copying, redistribution, sublicensing,63// publication and commercial exploitation are not permitted.64//65// Existing third-party rights and notices remain unaffected.66//67// =============================================================================68// CONFIDENTIALITY & SECURITY69// =============================================================================70//71// Classification : Public72// Distribution : Public repository; use is governed by the project license73// Security Contact : admin@spboucher.ai74//75// Access to this source does not independently grant permission76// to redistribute or disclose confidential materials.77//78// Do not embed credentials, private keys, access tokens,79// certificates or confidential personal information.80//81// =============================================================================82// LICENSE & MAINTENANCE83// =============================================================================84//85// License : None specified (no license file in this repository)86// Maintainer : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import SwiftUI9495struct CompareV3View: View {96 @Environment(AppModel.self) private var model97 @Environment(Library.self) private var library98 @Environment(\.dynamicTypeSize) private var typeSize99100 private var colWidth: CGFloat { typeSize.isAccessibilitySize ? 250 : 176 }101102 /// Axe commun des propriétés qui portent un montant.103 private var domain: ClosedRange<Double>? {104 IntervalBar.commonDomain(library.compare.compactMap { p in105 guard let v = p.valueBlock, let a = v.amounts else { return nil }106 return (a.low, a.high, v.isFirm && p.position != nil ? p.price : nil)107 })108 }109110 var body: some View {111 ScrollView {112 if library.compare.isEmpty {113 EmptyState(title: "Rien à comparer",114 message: "Ouvrez une fiche et touchez « Comparer ». Jusqu'à \(Library.compareLimit) propriétés se placent ici sur un même axe.")115 .padding(.top, 20)116 } else {117 VStack(alignment: .leading, spacing: 0) {118 VStack(alignment: .leading, spacing: 0) {119 SectionHeader("Sur un même axe", note: "Chaque trait est l'intervalle d'une propriété, le plomb sa valeur, le losange le prix qui lui est comparé. Trait tireté : ordre de grandeur.")120 ForEach(library.compare) { p in axisRow(p) }121 }122 .padding(.horizontal, Theme.margin)123124 SectionHeader("Côte à côte").padding(.horizontal, Theme.margin).padding(.top, 30)125 ScrollView(.horizontal, showsIndicators: false) {126 HStack(alignment: .top, spacing: 12) { ForEach(library.compare) { p in column(p) } }127 .padding(.horizontal, Theme.margin)128 }129 .padding(.top, 12)130 }131 .padding(.top, 8).padding(.bottom, 36)132 .frame(maxWidth: Theme.readable + 160)133 .frame(maxWidth: .infinity)134 }135 }136 .background(Theme.bg)137 .navigationTitle("Comparateur")138 .navigationBarTitleDisplayMode(.inline)139 .toolbar {140 if !library.compare.isEmpty {141 ToolbarItem(placement: .topBarTrailing) { Button("Vider") { withAnimation { library.clearCompare() } } }142 }143 }144 }145146 private func axisRow(_ p: SavedProperty) -> some View {147 Button { model.open(p) } label: {148 VStack(alignment: .leading, spacing: 6) {149 HStack(alignment: .firstTextBaseline, spacing: 10) {150 Text(p.title).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink).lineLimit(1)151 Spacer(minLength: 8)152 if let a = ValueFmt.amount(p.valueBlock) {153 Text(a).font(.subheadline.weight(.semibold)).num().foregroundStyle(Theme.ink)154 }155 }156 if let v = p.valueBlock, let a = v.amounts {157 IntervalBar(value: a.value, low: a.low, high: a.high, approximate: v.status == .ordre,158 price: v.isFirm && p.position != nil ? p.price : nil, domain: domain)159 if v.isFirm, p.price != nil, p.priceLabel != nil {160 PositionPlate(position: p.position, gapPct: p.ecartPct, size: .compact)161 }162 } else {163 NoteBlock(text: noValue(p), dashed: true)164 }165 }166 .padding(.vertical, 12)167 .overlay(alignment: .bottom) { Hairline() }168 .contentShape(Rectangle())169 }170 .buttonStyle(.plain)171 .accessibilityIdentifier("compare-axis-row")172 }173174 private func noValue(_ p: SavedProperty) -> String {175 guard let m = p.valueBlock?.motif else { return "Aucune valeur." }176 return "Aucune valeur : " + [m.familyTitle?.lowercased(), m.libelle.isEmpty ? nil : m.libelle].compactMap { $0 }.joined(separator: ", ") + "."177 }178179 private func column(_ p: SavedProperty) -> some View {180 let v = p.valueBlock181 return VStack(alignment: .leading, spacing: 0) {182 Text(p.kind == .listing ? "À vendre" : "Propriété").eyebrowStyle()183 Text(p.title).font(.editorial(17)).foregroundStyle(Theme.ink).lineLimit(3).fixedSize(horizontal: false, vertical: true)184 .frame(minHeight: 44, alignment: .topLeading).padding(.top, 4)185 Text(p.subtitle).font(.footnote).foregroundStyle(Theme.ink3).lineLimit(2).frame(minHeight: 34, alignment: .topLeading)186 cell(v?.status == .ordre ? "Ordre de grandeur" : "Valeur estimée", ValueFmt.amount(v) ?? "Aucune valeur", strong: true)187 cell("Intervalle", v?.amounts.map { "\(Fmt.compact($0.low)) à \(Fmt.compact($0.high))" } ?? Fmt.dash)188 cell(p.kind == .listing ? "Prix demandé, ramené" : (p.priceLabel == "Demandé" ? "Prix demandé, ramené" : "Dernière vente"),189 p.price == nil ? (p.kind == .unit ? "Aucune depuis 2021" : Fmt.dash) : Fmt.money(p.price))190 VStack(alignment: .leading, spacing: 4) {191 Text("Position du prix").font(.caption).foregroundStyle(Theme.ink3)192 if v?.isFirm == true, p.price != nil { PositionPlate(position: p.position, gapPct: p.ecartPct, size: .compact) }193 else { Text(v?.amounts == nil ? "Aucune valeur" : (p.price == nil ? Fmt.dash : "Sans verdict")).font(.subheadline).foregroundStyle(Theme.ink) }194 }195 .frame(maxWidth: .infinity, minHeight: 58, alignment: .leading)196 Hairline()197 cell("Fiabilité", v?.confidenceLabel?.replacingOccurrences(of: "Confiance ", with: "").capitalized ?? Fmt.dash)198 cell("Valeur au rôle", p.roll == nil ? Fmt.dash : Fmt.money(p.roll))199 cell("Année", p.year.map(String.init) ?? Fmt.dash)200 cell("Aire d'étages", p.areaM2 == nil ? Fmt.dash : Fmt.area(m2: p.areaM2, both: false))201 cell("Terrain", p.landM2 == nil ? Fmt.dash : Fmt.area(m2: p.landM2, both: false))202 Button("Ouvrir") { model.open(p) }.buttonStyle(SecondaryButtonStyle()).padding(.top, 12)203 Button("Retirer") { withAnimation { _ = library.toggleCompare(p) } }204 .font(.subheadline).foregroundStyle(Theme.ink3).frame(maxWidth: .infinity, minHeight: 44)205 }206 .frame(width: colWidth, alignment: .leading)207 .cardStyle(padding: 14)208 .accessibilityElement(children: .contain)209 }210211 private func cell(_ label: String, _ value: String, strong: Bool = false) -> some View {212 VStack(alignment: .leading, spacing: 0) {213 VStack(alignment: .leading, spacing: 3) {214 Text(label).font(.caption).foregroundStyle(Theme.ink3)215 Text(value).font(strong ? .body.weight(.semibold) : .subheadline).num().foregroundStyle(Theme.ink).lineLimit(2).minimumScaleFactor(0.8)216 }217 .frame(maxWidth: .infinity, minHeight: 50, alignment: .leading)218 Hairline()219 }220 }221}222