Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Vrai-Prix iOS9// File : VraiPrix/Features/Library/LibraryView.swift10// Description : favoris, comparateur et fiches récentes — tout reste sur11// l'appareil, aucun compte.12// Module : VraiPrix13// Repository : https://git.spboucher.ai/vrai-prix-ios-v314// Project Website : https://www.vrai-prix.com15// Created : 2026-11-2616// Last Modified : 2026-11-2617//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author : Simon-Pierre Boucher23// Position : Professor of Finance24// Institution : Université du Québec en Outaouais (UQO)25// Department : Département des sciences administratives26// Organization : SP Boucher27//28// Website : https://spboucher.ai29// Git : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General : info@spboucher.ai36// Professional : contact@spboucher.ai37// Direct : simon@spboucher.ai38// Research : research@spboucher.ai39// Development : dev@spboucher.ai40// Support : support@spboucher.ai41// Security/Admin : admin@spboucher.ai42// Notifications : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification : Public69// Distribution : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License : None specified (no license file in this repository)83// Maintainer : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import SwiftUI9192struct LibraryView: View {93 @Environment(AppModel.self) private var model94 @Environment(Library.self) private var library9596 var body: some View {97 ScrollView {98 VStack(alignment: .leading, spacing: 0) {99 if library.favorites.isEmpty {100 EmptyState(title: "Aucun favori",101 message: "Touchez le cœur d'une fiche pour la garder ici. Les favoris restent sur cet appareil et se consultent hors ligne.",102 actionLabel: "Chercher une adresse") { model.tab = .home }103 } else {104 Text("\(library.favorites.count) \(library.favorites.count == 1 ? "propriété gardée" : "propriétés gardées") sur cet appareil.")105 .font(.subheadline).num().foregroundStyle(Theme.ink3).padding(.bottom, 8)106 Hairline()107 ForEach(library.favorites) { f in108 HStack(spacing: 4) {109 Button { model.open(f) } label: { SavedRow(item: f) }.buttonStyle(.plain)110 Menu {111 Button(library.isCompared(f.id) ? "Retirer du comparateur" : "Comparer") {112 if library.toggleCompare(f) == .full { model.showToast("Le comparateur contient déjà \(Library.compareLimit) propriétés") }113 }114 Button("Retirer des favoris", role: .destructive) { withAnimation { library.removeFavorite(f.id) } }115 } label: {116 Image(systemName: "ellipsis").font(.body.weight(.medium)).foregroundStyle(Theme.ink3).frame(width: 40, height: 44)117 }118 .accessibilityLabel("Actions pour \(f.title)")119 }120 Hairline()121 }122 }123124 VStack(spacing: 0) {125 Hairline()126 NavRow(icon: .comparables, title: "Comparateur",127 detail: library.compare.isEmpty ? "Jusqu'à \(Library.compareLimit) propriétés côte à côte" : "\(library.compare.count) \(library.compare.count == 1 ? "propriété" : "propriétés")") { model.open(.compare) }128 NavRow(icon: .roleEvaluation, title: "Fiches récentes",129 detail: library.recents.isEmpty ? "Aucune fiche consultée" : "\(library.recents.count) consultées, lisibles hors ligne") { model.open(.recents) }130 NavRow(icon: .aplomb, title: "Réglages et à propos", detail: "Thème, animations, données sur l'appareil", divider: false) { model.open(.settings) }131 }132 .padding(.top, 30)133 }134 .pageColumn()135 .padding(.top, 6).padding(.bottom, 36)136 }137 .background(Theme.bg)138 .navigationTitle("Favoris")139 }140}141142struct RecentsView: View {143 @Environment(AppModel.self) private var model144 @Environment(Library.self) private var library145146 var body: some View {147 ScrollView {148 VStack(alignment: .leading, spacing: 0) {149 if library.recents.isEmpty {150 EmptyState(title: "Aucune fiche consultée", message: "Les fiches ouvertes apparaissent ici et restent lisibles hors ligne.")151 } else {152 Hairline()153 ForEach(library.recents) { r in154 Button { model.open(r) } label: { SavedRow(item: r) }.buttonStyle(.plain)155 Hairline()156 }157 }158 }159 .pageColumn()160 .padding(.top, 6).padding(.bottom, 36)161 }162 .background(Theme.bg)163 .navigationTitle("Fiches récentes")164 .navigationBarTitleDisplayMode(.inline)165 .toolbar {166 if !library.recents.isEmpty {167 ToolbarItem(placement: .topBarTrailing) { Button("Effacer") { library.clearRecents() } }168 }169 }170 }171}172173/// Comparateur : jusqu'à quatre propriétés, une colonne chacune, mêmes lignes, jauge sur la même logique.174struct CompareView: View {175 @Environment(AppModel.self) private var model176 @Environment(Library.self) private var library177 @Environment(\.dynamicTypeSize) private var typeSize178179 private var colWidth: CGFloat { typeSize.isAccessibilitySize ? 250 : 188 }180181 var body: some View {182 ScrollView {183 if library.compare.isEmpty {184 EmptyState(title: "Rien à comparer",185 message: "Ouvrez une fiche et touchez « Comparer ». Jusqu'à \(Library.compareLimit) propriétés se placent ici côte à côte.")186 .padding(.top, 20)187 } else {188 VStack(alignment: .leading, spacing: 14) {189 Text("Chaque colonne lit le prix contre la valeur estimée de la propriété. Faites défiler latéralement.")190 .font(.subheadline).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)191 .padding(.horizontal, Theme.margin)192 ScrollView(.horizontal, showsIndicators: false) {193 HStack(alignment: .top, spacing: 12) {194 ForEach(library.compare) { p in column(p) }195 }196 .padding(.horizontal, Theme.margin)197 }198 }199 .padding(.top, 8).padding(.bottom, 36)200 }201 }202 .background(Theme.bg)203 .navigationTitle("Comparateur")204 .navigationBarTitleDisplayMode(.inline)205 .toolbar {206 if !library.compare.isEmpty {207 ToolbarItem(placement: .topBarTrailing) { Button("Vider") { withAnimation { library.clearCompare() } } }208 }209 }210 }211212 private func column(_ p: SavedProperty) -> some View {213 VStack(alignment: .leading, spacing: 0) {214 Text(p.kind == .listing ? "À vendre" : "Estimation").eyebrowStyle()215 Text(p.title).font(.editorial(18)).foregroundStyle(Theme.ink).lineLimit(3).fixedSize(horizontal: false, vertical: true)216 .frame(minHeight: 46, alignment: .topLeading).padding(.top, 4)217 Text(p.subtitle).font(.footnote).foregroundStyle(Theme.ink3).lineLimit(2).frame(minHeight: 34, alignment: .topLeading)218219 if let v = p.value, let lo = p.low, let hi = p.high, v > 0 {220 MiniGauge(scale: GaugeScale(value: v, low: lo, high: hi, price: p.gapPct == nil ? nil : p.price), background: Theme.surface)221 .padding(.top, 8)222 } else {223 Rectangle().fill(Theme.line).frame(height: 1).padding(.vertical, 11.5).padding(.top, 8)224 }225 cell("Valeur estimée", Fmt.money(p.value), strong: true)226 cell("Fourchette", p.low != nil ? "\(Fmt.compact(p.low)) à \(Fmt.compact(p.high))" : Fmt.dash)227 cell(p.kind == .listing ? "Prix demandé" : "Dernière vente", p.price == nil && p.kind == .unit ? "Aucune depuis 2021" : Fmt.money(p.price))228 VStack(alignment: .leading, spacing: 4) {229 Text("Lecture").font(.caption).foregroundStyle(Theme.ink3)230 if let r = p.reading { VerdictTag(verdict: r.verdict, gapPct: r.gapPct) } else { Text(Fmt.dash).font(.subheadline).foregroundStyle(Theme.ink) }231 }232 .frame(maxWidth: .infinity, minHeight: 58, alignment: .leading)233 Hairline()234 cell("Fiabilité", p.confidence.map { "\($0) · \(Confidence.label($0))" } ?? Fmt.dash)235 cell("Rôle d'évaluation", Fmt.money(p.roll))236 cell("Année", p.year.map(String.init) ?? Fmt.dash)237 cell("Aire habitable", Fmt.area(m2: p.areaM2, both: false))238 cell("Terrain", Fmt.area(m2: p.landM2, both: false))239240 Button("Ouvrir") { model.open(p) }.buttonStyle(SecondaryButtonStyle()).padding(.top, 12)241 Button("Retirer") { withAnimation { _ = library.toggleCompare(p) } }242 .font(.subheadline).foregroundStyle(Theme.ink3).frame(maxWidth: .infinity, minHeight: 44)243 }244 .frame(width: colWidth, alignment: .leading)245 .cardStyle(padding: 14)246 .accessibilityElement(children: .contain)247 }248249 private func cell(_ label: String, _ value: String, strong: Bool = false) -> some View {250 VStack(alignment: .leading, spacing: 0) {251 VStack(alignment: .leading, spacing: 2) {252 Text(label).font(.caption).foregroundStyle(Theme.ink3)253 Text(value).font(strong ? .body.weight(.semibold) : .subheadline.weight(.medium)).num().foregroundStyle(Theme.ink)254 .lineLimit(1).minimumScaleFactor(0.7)255 }256 .frame(maxWidth: .infinity, minHeight: 48, alignment: .leading)257 Hairline()258 }259 .accessibilityElement(children: .combine)260 }261}262