Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Immo-Ka iOS9// File : ImmoKa/Features/Listing/ListingSectionsV3.swift10// Description : blocs de la fiche servis par l'API v3 — prix de vente11// attendu et position du prix demandé, coût de possession,12// ventes réelles et inscriptions comparables, même propriété13// ailleurs, statut, inscription retirée. Chaque montant dit14// d'où il vient ; une valeur inconnue ne s'écrit jamais15// zéro.16// Module : ImmoKa17// Repository : https://git.spboucher.ai/immo-ka-ios-v318// Project Website : https://www.immo-ka.com19// Created : 2026-11-2820// Last Modified : 2026-11-2821//22// =============================================================================23// AUTHOR & PROFESSIONAL AFFILIATION24// =============================================================================25//26// Author : Simon-Pierre Boucher27// Position : Professor of Finance28// Institution : Université du Québec en Outaouais (UQO)29// Department : Département des sciences administratives30// Organization : SP Boucher31//32// Website : https://spboucher.ai33// Git : https://git.spboucher.ai34//35// =============================================================================36// OFFICIAL CONTACT DIRECTORY37// =============================================================================38//39// General : info@spboucher.ai40// Professional : contact@spboucher.ai41// Direct : simon@spboucher.ai42// Research : research@spboucher.ai43// Development : dev@spboucher.ai44// Support : support@spboucher.ai45// Security/Admin : admin@spboucher.ai46// Notifications : notifications@spboucher.ai47//48// Preferred Contact: support@spboucher.ai49//50// =============================================================================51// COPYRIGHT & INTELLECTUAL PROPERTY52// =============================================================================53//54// Copyright (c) 202655// Simon-Pierre Boucher56//57// All rights reserved where applicable.58//59// This file is governed by the applicable project license,60// copyright notices, institutional agreements and relevant law.61//62// Unless expressly authorized by the applicable license or63// rights holder, copying, redistribution, sublicensing,64// publication and commercial exploitation are not permitted.65//66// Existing third-party rights and notices remain unaffected.67//68// =============================================================================69// CONFIDENTIALITY & SECURITY70// =============================================================================71//72// Classification : Public73// Distribution : Public repository; use is governed by the project license74// Security Contact : admin@spboucher.ai75//76// Access to this source does not independently grant permission77// to redistribute or disclose confidential materials.78//79// Do not embed credentials, private keys, access tokens,80// certificates or confidential personal information.81//82// =============================================================================83// LICENSE & MAINTENANCE84// =============================================================================85//86// License : None specified (no license file in this repository)87// Maintainer : Simon-Pierre Boucher88// Technical Contact: dev@spboucher.ai89//90// =============================================================================91// END OF SP BOUCHER SOURCE HEADER92// =============================================================================9394import SwiftUI9596/// Étiquette de provenance : observé, estimé, saisi, hypothèse, inconnu (glyphe et libellé, jamais la couleur seule).97struct ProvenanceTag: View {98 let status: Provenance99 var body: some View {100 HStack(spacing: 3) {101 Image(systemName: status.symbol).font(.system(size: 9, weight: .semibold))102 Text(status.label)103 }104 .font(.caption2.weight(.medium))105 .foregroundStyle(status == .estime ? Theme.high : Theme.ink3)106 .padding(.horizontal, 6).padding(.vertical, 3)107 .overlay(RoundedRectangle(cornerRadius: 4, style: .continuous)108 .strokeBorder(Theme.line2, style: StrokeStyle(lineWidth: 1, dash: status == .hypothese || status == .inconnu ? [3, 2] : [])))109 .accessibilityLabel(status.label)110 }111}112113/// Filet de faîte : coiffe un bloc de données (2 points, charbon).114struct Larmier: View {115 var body: some View { Rectangle().fill(Theme.ink).frame(height: 2) }116}117118// MARK: - Statut et activité119120/// Statut donné par la source, baisse de prix observée, durée d'affichage et sa réserve.121struct MarketStatusSection: View {122 let listing: Listing123124 var body: some View {125 let l = listing126 let rows = lines(l)127 if !rows.isEmpty {128 VStack(alignment: .leading, spacing: 8) {129 ForEach(rows, id: \.text) { r in130 Label {131 Text(r.text).font(.footnote).num().foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)132 } icon: {133 Image(systemName: r.icon).font(.footnote).foregroundStyle(r.tint)134 }135 }136 }137 .padding(.bottom, 26)138 .accessibilityIdentifier("listing.status")139 }140 }141142 private func lines(_ l: Listing) -> [(icon: String, text: String, tint: Color)] {143 var out: [(String, String, Color)] = []144 if let s = l.statusLabel {145 let when = l.statusObservedAt.map { ", observé le \(Fmt.date($0))" } ?? ""146 out.append(("flag", "\(s) selon la source\(when).", Theme.high))147 }148 if let d = l.priceDrop, let prev = l.pricePrev {149 let when = l.priceChangedAt.map { " le \(Fmt.date($0))" } ?? ""150 out.append(("arrow.down", "Prix baissé de \(Fmt.money(abs(d)))\(when) (\(Fmt.money(prev)) auparavant).", Theme.good))151 }152 if l.marketCensored {153 out.append(("clock", "Déjà en ligne au premier passage d'Immo-Ka : la date de mise en marché est inconnue.", Theme.ink3))154 }155 return out156 }157}158159/// Attributs à trois états : ce que la source déclare (oui ou non). Ce qu'elle ne dit pas est inconnu et n'est pas listé.160struct FlagsSection: View {161 let listing: Listing162163 var body: some View {164 let known = SearchFilters.attributes.compactMap { a in listing.flags[a.key].map { (a, $0) } }165 if !known.isEmpty {166 VStack(alignment: .leading, spacing: 12) {167 SectionHeader(title: "Ce que la source déclare",168 subtitle: "Une caractéristique absente de cette liste est inconnue, pas exclue.")169 FlowLayout(spacing: 8) {170 ForEach(known, id: \.0.key) { a, yes in171 HStack(spacing: 6) {172 Image(systemName: yes ? "checkmark" : "xmark").font(.system(size: 10, weight: .bold))173 Text(a.label).strikethrough(!yes)174 }175 .font(.footnote.weight(.medium))176 .foregroundStyle(yes ? Theme.ink : Theme.ink3)177 .padding(.horizontal, 11).padding(.vertical, 7)178 .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))179 .accessibilityElement(children: .ignore)180 .accessibilityLabel("\(a.label) : \(yes ? "oui" : "non")")181 }182 }183 }184 .padding(.bottom, 30)185 }186 }187}188189// MARK: - Prix de vente attendu190191struct ValuationSection: View {192 let listing: Listing193 @State private var valuation: Valuation?194 @State private var failed = false195 @State private var showLimits = false196197 var body: some View {198 let l = listing199 // la section existe dès que la liste porte une estimation ; le détail arrive ensuite200 if l.estimate != nil || valuation != nil || !failed, l.plausiblePrice != nil {201 VStack(alignment: .leading, spacing: 16) {202 SectionHeader(title: "Prix de vente attendu",203 subtitle: "D'après les ventes réelles de propriétés semblables. Ce n'est ni une évaluation agréée ni une promesse.") {204 NavigationLink(value: Route.vraiPrixGuide) { Image(systemName: "info.circle").foregroundStyle(Theme.ink3) }205 .accessibilityLabel("Comment le prix de vente attendu est estimé")206 }207 if let e = expected {208 main(l, e)209 } else if let v = valuation {210 abstention(v)211 } else if !failed {212 Skeleton(height: 96, radius: Theme.radius)213 }214 if let v = valuation { detail(l, v) }215 }216 .padding(.bottom, 30)217 .task(id: l.uid) {218 guard valuation == nil else { return }219 do { valuation = try await APIClient.shared.valuation(l.uid) } catch { failed = true }220 }221 .accessibilityIdentifier("listing.valuation")222 }223 }224225 /// Intervalle à afficher : celui du détail quand il est arrivé, sinon celui de la liste.226 private var expected: (value: Double, low: Double?, high: Double?, level: String)? {227 if let e = valuation?.expected {228 let lvl = e.level.map { "\(Int(($0 * 10).rounded())) ventes sur 10" } ?? "la plupart des ventes"229 return (e.value, e.low, e.high, lvl)230 }231 if valuation == nil, let e = listing.estimate { return (e.value, e.low, e.high, e.levelLabel) }232 return nil233 }234235 private var position: (verdict: Verdict, gap: Double?)? {236 if let v = valuation { return v.position.map { ($0, v.gapPct) } }237 return listing.verdictInfo.map { ($0.verdict, $0.deviation * 100) }238 }239240 @ViewBuilder241 private func main(_ l: Listing, _ e: (value: Double, low: Double?, high: Double?, level: String)) -> some View {242 VStack(alignment: .leading, spacing: 14) {243 Larmier()244 HStack(alignment: .firstTextBaseline) {245 VStack(alignment: .leading, spacing: 3) {246 ProvenanceTag(status: .estime)247 Text(Fmt.money(e.value)).font(.display(28, weight: .semibold)).num().foregroundStyle(Theme.ink)248 }249 Spacer()250 if let p = position {251 VerdictPill(verdict: p.verdict, deviation: p.gap.map { $0 / 100 }, large: true)252 } else {253 UncertainPill()254 }255 }256 if let low = e.low, let high = e.high, high > low, let price = l.plausiblePrice {257 FairValueGauge(price: price, fv: e.value, low: low, high: high, verdict: position?.verdict)258 Text("\(e.level.prefix(1).uppercased() + e.level.dropFirst()) se concluent entre \(Fmt.money(low)) et \(Fmt.money(high)).")259 .font(.subheadline).num().foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)260 }261 if let t = valuation?.positionText {262 Text(t).font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)263 } else if valuation != nil, position == nil {264 let why = valuation?.positionAbsentReasons.first265 Text("Aucune position n'est donnée pour ce prix demandé\(why.map { " : \($0.prefix(1).lowercased() + $0.dropFirst())" } ?? " : l'estimation est trop incertaine").")266 .font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)267 }268 }269 }270271 private func abstention(_ v: Valuation) -> some View {272 VStack(alignment: .leading, spacing: 8) {273 HStack(spacing: 8) {274 UncertainPill()275 Text("Pas d'estimation pour cette propriété").font(.subheadline.weight(.semibold)).foregroundStyle(Theme.ink)276 }277 Text(v.absentReason ?? "Les données ne suffisent pas pour estimer un prix de vente : l'app ne montre rien plutôt que d'inventer.")278 .font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)279 }280 }281282 @ViewBuilder283 private func detail(_ l: Listing, _ v: Valuation) -> some View {284 if let p = v.probable, let price = l.plausiblePrice {285 VStack(alignment: .leading, spacing: 6) {286 Text("Compte tenu du prix demandé").font(.caption.weight(.semibold)).foregroundStyle(Theme.ink3)287 HStack(alignment: .firstTextBaseline) {288 Text(Fmt.money(p.value)).font(.display(20, weight: .semibold)).num().foregroundStyle(Theme.ink)289 if let lo = p.low, let hi = p.high {290 Text("de \(Fmt.money(lo)) à \(Fmt.money(hi))").font(.footnote).num().foregroundStyle(Theme.ink3)291 }292 }293 if let r = v.saleToAskRatio, let n = v.pairs {294 Text("Sur \(Fmt.int(n)) inscriptions reliées à leur vente, une propriété se vend en médiane à \(Fmt.decimal(r * 100)) % de son prix demandé (ici \(Fmt.money(price))).")295 .font(.footnote).num().foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)296 }297 }298 }299 if !v.effects.isEmpty, let ref = v.reference {300 VStack(alignment: .leading, spacing: 8) {301 Text("Ce qui fait l'estimation").font(.caption.weight(.semibold)).foregroundStyle(Theme.ink3)302 VStack(spacing: 0) {303 KeyValueRow(label: "Propriété médiane du marché", value: Fmt.money(ref))304 Divider().overlay(Theme.line)305 ForEach(v.effects) { e in306 KeyValueRow(label: e.label, value: (e.effect >= 0 ? "+ " : "− ") + Fmt.money(abs(e.effect)))307 Divider().overlay(Theme.line)308 }309 if let exp = v.expected { KeyValueRow(label: "Prix de vente attendu", value: Fmt.money(exp.value)) }310 }311 }312 }313 let facts = factRows(l, v)314 if !facts.isEmpty { RowList(rows: facts) }315 ForEach(v.warnings, id: \.self) { w in316 Label(w, systemImage: "exclamationmark.triangle").font(.footnote).foregroundStyle(Theme.high).fixedSize(horizontal: false, vertical: true)317 }318 if !v.limits.isEmpty {319 VStack(alignment: .leading, spacing: 8) {320 Button {321 withAnimation(.snappy) { showLimits.toggle() }322 } label: {323 HStack(spacing: 6) {324 Text("Limites de l'estimation").font(.subheadline.weight(.semibold))325 Image(systemName: "chevron.down").font(.caption.weight(.bold)).rotationEffect(.degrees(showLimits ? 180 : 0))326 }327 }328 .accessibilityIdentifier("valuation.limits")329 if showLimits {330 ForEach(v.limits, id: \.self) { t in331 HStack(alignment: .firstTextBaseline, spacing: 8) {332 Text("–").foregroundStyle(Theme.ink3)333 Text(t).fixedSize(horizontal: false, vertical: true)334 }335 .font(.footnote).foregroundStyle(Theme.ink2)336 }337 }338 }339 }340 if let m = v.modelVersion {341 Text("Modèle \(m)\(v.salesUntil.map { ", ventes connues jusqu'au \(Fmt.day($0))" } ?? "").")342 .font(.caption).num().foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)343 }344 }345346 private func factRows(_ l: Listing, _ v: Valuation) -> [(String, String)] {347 var rows: [(String, String)] = []348 if let c = v.confidence { rows.append(("Confiance", c.prefix(1).uppercased() + c.dropFirst())) }349 if let n = v.salesWithin1km { rows.append(("Ventes comparables à 1 km", Fmt.int(n))) }350 if let r = v.rollValue ?? l.vraiprix?.valeurRole {351 rows.append(("Valeur au rôle\(v.rollDate.map { " (\($0.prefix(4)))" } ?? "")", Fmt.money(r)))352 }353 if let t = l.vraiprix?.valeurTerrain { rows.append(("dont terrain", Fmt.money(t))) }354 if let b = l.vraiprix?.valeurBatiment { rows.append(("dont bâtiment", Fmt.money(b))) }355 return rows356 }357}358359/// Position incertaine : pierre, contour pointillé.360struct UncertainPill: View {361 var body: some View {362 HStack(spacing: 4) {363 Image(systemName: "questionmark").font(.system(size: 11, weight: .bold))364 Text("Incertain")365 }366 .font(.system(size: 14, weight: .semibold))367 .foregroundStyle(Theme.ink3)368 .padding(.horizontal, 12).padding(.vertical, 7)369 .overlay(RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous).strokeBorder(Theme.ink3, style: StrokeStyle(lineWidth: 1, dash: [3, 2])))370 .accessibilityLabel("Position du prix incertaine")371 }372}373374// MARK: - Coût de possession375376struct OwnershipSection: View {377 let listing: Listing378 @State private var data: Ownership?379 @State private var assumptions = OwnershipAssumptions()380 @State private var loading = false381 @State private var failed = false382 @State private var showPurchase = false383384 private static let downs: [Double] = [5, 10, 20, 35]385 private static let amortizations = [25, 30]386387 var body: some View {388 if listing.plausiblePrice != nil, !failed || data != nil {389 VStack(alignment: .leading, spacing: 16) {390 SectionHeader(title: "Coût de possession",391 subtitle: "Ce que cette propriété coûterait chaque mois, poste par poste, et le comptant à réunir.") {392 NavigationLink(value: Route.rates) { Text("Taux").font(.subheadline.weight(.semibold)) }393 }394 if let d = data {395 if d.applicable, let m = d.monthly {396 monthly(d, m)397 controls(d)398 purchase(d)399 ForEach(d.warnings, id: \.self) { w in400 Label(w, systemImage: "exclamationmark.triangle").font(.footnote).foregroundStyle(Theme.high).fixedSize(horizontal: false, vertical: true)401 }402 if let t = d.method {403 Text(t).font(.caption).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)404 }405 } else {406 Text(d.scopeMessage ?? "Le coût de possession n'est pas calculé pour ce type de propriété.")407 .font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)408 }409 } else {410 Skeleton(height: 180, radius: Theme.radius)411 }412 }413 .padding(.bottom, 30)414 .task(id: assumptions) { await load() }415 .accessibilityIdentifier("listing.ownership")416 }417 }418419 private func load() async {420 loading = true421 defer { loading = false }422 do {423 let d = try await APIClient.shared.ownership(listing.uid, assumptions: assumptions)424 withAnimation(.snappy) { data = d }425 } catch is CancellationError {426 } catch {427 if data == nil { failed = true }428 }429 }430431 private func monthly(_ d: Ownership, _ m: Ownership.Total) -> some View {432 VStack(alignment: .leading, spacing: 12) {433 Larmier()434 VStack(alignment: .leading, spacing: 3) {435 Text(m.atLeast ? "Au moins, par mois" : "Par mois").font(.caption).foregroundStyle(Theme.ink3)436 Text(Fmt.money(m.amount)).font(.display(30, weight: .semibold)).num().foregroundStyle(Theme.ink)437 .contentTransition(.numericText())438 if let lo = m.low, let hi = m.high, hi > lo {439 Text("Fourchette : de \(Fmt.money(lo)) à \(Fmt.money(hi))").font(.footnote).num().foregroundStyle(Theme.ink3)440 }441 }442 .opacity(loading ? 0.55 : 1)443 VStack(spacing: 0) {444 ForEach(d.monthlyLines) { line in445 lineRow(line)446 Divider().overlay(Theme.line)447 }448 }449 if !m.notCounted.isEmpty {450 Text("Non compté : \(m.notCounted.joined(separator: ", ").lowercased()). Le total est un minimum.")451 .font(.footnote).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)452 }453 }454 }455456 private func lineRow(_ line: Ownership.Line) -> some View {457 VStack(alignment: .leading, spacing: 4) {458 HStack(alignment: .firstTextBaseline, spacing: 8) {459 Text(line.label).font(.subheadline).foregroundStyle(Theme.ink)460 ProvenanceTag(status: line.amount == nil ? .inconnu : line.status)461 Spacer(minLength: 8)462 // un poste inconnu ne s'écrit jamais zéro463 Text(line.amount.map { Fmt.money($0) } ?? "Inconnu").font(.subheadline.weight(.medium)).num()464 .foregroundStyle(line.amount == nil ? Theme.ink3 : Theme.ink)465 }466 if let lo = line.low, let hi = line.high, hi > lo {467 Text("de \(Fmt.money(lo)) à \(Fmt.money(hi))").font(.caption).num().foregroundStyle(Theme.ink3)468 }469 }470 .padding(.vertical, 9)471 .accessibilityElement(children: .combine)472 }473474 private func controls(_ d: Ownership) -> some View {475 VStack(alignment: .leading, spacing: 10) {476 Text("Vos hypothèses").font(.caption.weight(.semibold)).foregroundStyle(Theme.ink3)477 FlowLayout(spacing: 8) {478 ForEach(Self.downs, id: \.self) { p in479 Chip(label: "Mise de fonds \(Int(p)) %", active: abs((assumptions.downPct ?? d.downPct ?? 20) - p) < 0.01) {480 assumptions.downPct = p481 }482 }483 ForEach(Self.amortizations, id: \.self) { a in484 Chip(label: "\(a) ans", active: (assumptions.amortization ?? d.amortization ?? 25) == a) {485 assumptions.amortization = a486 }487 }488 }489 if let r = d.rate {490 Text("Taux de \(Fmt.rate(r))\(d.ratesObserved.map { ", médiane de \($0) offres observées" } ?? "")\(d.insured == true ? ". Prêt assuré : la prime s'ajoute au prêt" : "").\(d.stressPayment.map { " Au taux de qualification\(d.stressRate.map { " (\(Fmt.rate($0)))" } ?? "") : \(Fmt.money($0)) par mois." } ?? "")")491 .font(.footnote).num().foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)492 }493 }494 }495496 @ViewBuilder497 private func purchase(_ d: Ownership) -> some View {498 if let c = d.cash {499 VStack(alignment: .leading, spacing: 8) {500 Button {501 withAnimation(.snappy) { showPurchase.toggle() }502 } label: {503 HStack(alignment: .firstTextBaseline) {504 VStack(alignment: .leading, spacing: 2) {505 Text(c.atLeast ? "Comptant à réunir, au moins" : "Comptant à réunir").font(.caption).foregroundStyle(Theme.ink3)506 Text(Fmt.money(c.amount)).font(.display(20, weight: .semibold)).num().foregroundStyle(Theme.ink)507 .contentTransition(.numericText())508 }509 Spacer()510 Image(systemName: "chevron.down").font(.caption.weight(.bold)).rotationEffect(.degrees(showPurchase ? 180 : 0))511 }512 .contentShape(Rectangle())513 }514 .buttonStyle(.plain)515 .accessibilityIdentifier("ownership.cash")516 if showPurchase {517 VStack(spacing: 0) {518 ForEach(d.purchaseLines) { line in519 lineRow(line)520 Divider().overlay(Theme.line)521 }522 }523 if let n = d.purchaseNote {524 Text(n).font(.caption).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)525 }526 }527 }528 }529 }530}531532// MARK: - Comparables : ventes réelles, puis inscriptions actives533534struct ComparablesV3Section: View {535 let listing: Listing536 @Environment(AppModel.self) private var app537538 var body: some View {539 let uid = listing.uid540 LazyLoad(id: "comp3-\(uid)") { () async throws -> Comparables? in541 let c = try await APIClient.shared.comparablesV3(uid)542 return c.sold.isEmpty && c.active.isEmpty ? nil : c543 } content: { c in544 VStack(alignment: .leading, spacing: 22) {545 if !c.sold.isEmpty {546 VStack(alignment: .leading, spacing: 12) {547 SectionHeader(title: "Ventes réelles comparables",548 subtitle: "Prix de vente tirés des actes publiés, ajustés à la date la plus récente de l'indice.")549 VStack(spacing: 0) {550 ForEach(c.sold) { s in551 soldRow(s)552 Divider().overlay(Theme.line)553 }554 }555 }556 }557 if !c.active.isEmpty {558 VStack(alignment: .leading, spacing: 12) {559 SectionHeader(title: "À vendre dans les environs",560 subtitle: "Prix demandés d'inscriptions actives : ce ne sont pas des prix de vente.")561 VStack(spacing: 0) {562 ForEach(c.active) { a in563 Button { app.open(.listing(a.uid)) } label: { activeRow(a) }564 .buttonStyle(.plain)565 Divider().overlay(Theme.line)566 }567 }568 }569 }570 if let t = c.limits {571 Text(t).font(.caption).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)572 }573 }574 .accessibilityIdentifier("listing.comparables")575 }576 }577578 private func meta(_ parts: [String?]) -> String { parts.compactMap { $0 }.joined(separator: " · ") }579580 private func soldRow(_ s: Comparables.Sold) -> some View {581 HStack(alignment: .firstTextBaseline, spacing: 12) {582 VStack(alignment: .leading, spacing: 3) {583 Text(s.address).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)584 Text(meta([s.saleDate.map { "Vendue le \(Fmt.day($0))" }, s.distanceM.map { Fmt.distance($0) },585 s.areaM2.map { "\(Fmt.int($0 * 10.7639)) pi²" }, s.yearBuilt.map(String.init),586 s.sameProperty ? "même propriété" : s.comparability.map { "comparabilité \($0)" }]))587 .font(.caption).num().foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)588 }589 Spacer(minLength: 8)590 VStack(alignment: .trailing, spacing: 3) {591 Text(Fmt.money(s.salePrice)).font(.subheadline.weight(.semibold)).num().foregroundStyle(Theme.ink)592 if let a = s.adjustedPrice, abs(a - s.salePrice) >= 500 {593 Text("ajusté : \(Fmt.money(a))").font(.caption).num().foregroundStyle(Theme.ink3)594 }595 }596 }597 .padding(.vertical, 10)598 .accessibilityElement(children: .combine)599 }600601 private func activeRow(_ a: Comparables.Active) -> some View {602 HStack(alignment: .firstTextBaseline, spacing: 12) {603 VStack(alignment: .leading, spacing: 3) {604 Text(a.address).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)605 Text(meta([a.type, a.city.map { Fmt.cleanCity($0) }, a.distanceM.map { Fmt.distance($0) },606 a.bedrooms.map { "\($0) ch." }, a.yearBuilt.map(String.init)]))607 .font(.caption).num().foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)608 }609 Spacer(minLength: 8)610 VStack(alignment: .trailing, spacing: 3) {611 Text(a.askPrice.map { Fmt.money($0) } ?? "Prix sur demande").font(.subheadline.weight(.semibold)).num().foregroundStyle(Theme.ink)612 Text("demandé").font(.caption).foregroundStyle(Theme.ink3)613 }614 Image(systemName: "chevron.right").font(.caption.weight(.semibold)).foregroundStyle(Theme.ink3)615 }616 .padding(.vertical, 10)617 .contentShape(Rectangle())618 .accessibilityElement(children: .combine)619 .accessibilityAddTraits(.isButton)620 }621}622623// MARK: - Même propriété ailleurs624625struct SamePropertySection: View {626 let listing: Listing627 @Binding var external: ExternalLink?628 @Environment(AppModel.self) private var app629630 var body: some View {631 let uid = listing.uid632 LazyLoad(id: "links-\(uid)") { () async throws -> ListingLinks? in633 let l = try await APIClient.shared.links(uid)634 return l.same.isEmpty && l.probable.isEmpty && l.republications.isEmpty ? nil : l635 } content: { links in636 VStack(alignment: .leading, spacing: 12) {637 SectionHeader(title: "Même propriété ailleurs",638 subtitle: "Les autres publications de cette propriété, et ce qui permet de les rapprocher.")639 VStack(spacing: 0) {640 ForEach(links.same) { row($0, tag: "Même propriété") }641 ForEach(links.probable) { row($0, tag: "Probable, non fusionnée") }642 ForEach(links.republications) { row($0, tag: "Republication") }643 }644 }645 .accessibilityIdentifier("listing.links")646 }647 }648649 private func row(_ l: ListingLinks.Link, tag: String) -> some View {650 Button { if let e = ExternalLink(l.url) { external = e } } label: {651 HStack(alignment: .firstTextBaseline, spacing: 12) {652 VStack(alignment: .leading, spacing: 3) {653 HStack(spacing: 8) {654 Text(app.sourceName(l.source)).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)655 Text(tag).font(.caption2.weight(.medium)).foregroundStyle(Theme.ink3)656 .padding(.horizontal, 6).padding(.vertical, 3)657 .overlay(RoundedRectangle(cornerRadius: 4, style: .continuous).strokeBorder(Theme.line2, style: StrokeStyle(lineWidth: 1, dash: l.merged ? [] : [3, 2])))658 }659 if let e = l.explanation.first {660 Text(e).font(.caption).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true).multilineTextAlignment(.leading)661 }662 }663 Spacer(minLength: 8)664 if let p = l.price, Listing.priceIsPlausible(p) {665 Text(Fmt.money(p)).font(.subheadline.weight(.medium)).num().foregroundStyle(Theme.ink)666 }667 if ExternalLink(l.url) != nil {668 Image(systemName: "arrow.up.right").font(.caption.weight(.semibold)).foregroundStyle(Theme.ink3)669 }670 }671 .padding(.vertical, 10)672 .contentShape(Rectangle())673 }674 .buttonStyle(.plain)675 .disabled(ExternalLink(l.url) == nil)676 .overlay(alignment: .bottom) { Divider().overlay(Theme.line) }677 }678}679680// MARK: - Inscription retirée (410)681682struct GoneListingView: View {683 let gone: GoneListing684 @Environment(AppModel.self) private var app685686 var body: some View {687 VStack(spacing: 14) {688 BrandIllustration(kind: .closed).padding(.bottom, 4)689 Text(gone.status == "vendu" ? "Propriété vendue" : "Inscription retirée")690 .font(.editorial(23)).foregroundStyle(Theme.ink).multilineTextAlignment(.center)691 if let t = gone.title {692 Text([t, gone.city.flatMap { t.localizedCaseInsensitiveContains($0) ? nil : $0 }].compactMap { $0 }.joined(separator: ", "))693 .font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink2).multilineTextAlignment(.center)694 }695 Text(gone.sentence).font(.subheadline).foregroundStyle(Theme.ink3).multilineTextAlignment(.center)696 if let d = gone.lastSeen {697 Text("Dernière observation : \(Fmt.date(d)).").font(.footnote).num().foregroundStyle(Theme.ink3)698 }699 if let c = gone.city {700 Button("Voir les propriétés à \(c)") {701 var f = SearchFilters(); f.city = c702 app.explore(f)703 }704 .buttonStyle(SoftButtonStyle()).padding(.top, 4)705 }706 }707 .padding(32)708 .frame(maxWidth: 440)709 .frame(maxWidth: .infinity)710 .accessibilityIdentifier("listing.gone")711 }712}713