Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka iOS9// File : LouKa/Design/ListingCard.swift10// Description : carte d'annonce — photo, verdict de prix, loyer, faits11// clés ; variantes grille et ligne.12// Module : LouKa13// Repository : https://git.spboucher.ai/lou-ka-ios-v314// Project Website : https://www.lou-ka.com15// Created : 2026-11-2516// Last Modified : 2026-11-2817//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 FavoriteButton: View {93 let listing: Listing94 var size: CGFloat = 3895 @Environment(Library.self) private var library96 @Environment(AppModel.self) private var model9798 var body: some View {99 let fav = library.isFavorite(listing.uid)100 GlassIconButton(system: fav ? "heart.fill" : "heart", tint: fav ? Theme.heart : Theme.ink, size: size,101 label: fav ? "Retirer des favoris" : "Ajouter aux favoris") {102 let added = library.toggleFavorite(listing)103 if added { Haptics.success() } else { Haptics.tap() }104 model.showToast(added ? "Ajouté à vos favoris" : "Retiré des favoris")105 }106 .heartBurst(fav)107 }108}109110/// Loyer mensuel en grand, ou « Prix sur demande ».111struct PriceText: View {112 let price: Double?113 var size: CGFloat = 24114 var body: some View {115 if let p = price, Listing.priceIsPlausible(p) {116 HStack(alignment: .firstTextBaseline, spacing: 4) {117 Text(Fmt.money(p)).font(.display(size, weight: .semibold)).tracking(-0.6).num().foregroundStyle(Theme.ink)118 Text("/ mois").font(.caption).foregroundStyle(Theme.ink3)119 }120 .accessibilityElement(children: .ignore)121 .accessibilityLabel("\(Fmt.money(p)) par mois")122 } else {123 Text("Prix sur demande").font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink2)124 }125 }126}127128struct ListingFacts: View {129 let listing: Listing130 var body: some View {131 let items: [(String, String)] = [132 listing.areaSqft.map { ("ruler", "\(Fmt.int($0)) pi²") },133 Fmt.availability(listing.availabilityDate).map { ("calendar", $0) },134 listing.petsAllowed ? ("pawprint", "Animaux") : nil,135 listing.furnished == true ? ("sofa", "Meublé") : nil,136 ].compactMap { $0 }137 if !items.isEmpty {138 HStack(spacing: 12) {139 ForEach(items.prefix(3), id: \.1) { icon, text in140 Label(text, systemImage: icon).labelStyle(.titleAndIcon).lineLimit(1)141 }142 }143 .font(.caption)144 .foregroundStyle(Theme.ink3)145 }146 }147}148149struct ListingCard: View {150 enum Layout { case grid, row }151 let listing: Listing152 var layout: Layout = .grid153154 @Environment(Library.self) private var library155 @Environment(AppModel.self) private var model156157 var body: some View {158 Group {159 switch layout {160 case .grid: grid161 case .row: row162 }163 }164 .background(Theme.surface, in: RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))165 .overlay(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous).strokeBorder(Theme.line, lineWidth: 1))166 .clipShape(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))167 .contentShape(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))168 .accessibilityElement(children: .combine)169 .accessibilityHint("Ouvre la fiche du logement")170 }171172 private var photo: some View {173 RemoteImage(source: listing.images.first, width: .small)174 .overlay(alignment: .topLeading) {175 HStack(spacing: 6) {176 VerdictPill(verdict: listing.fvVerdict, deviation: layout == .grid ? listing.fvDeviation : nil, onPhoto: true)177 if library.seenIDs.contains(listing.uid) {178 Text("Vu").font(.system(size: 11.5, weight: .semibold)).foregroundStyle(Theme.ink2)179 .padding(.horizontal, 9).padding(.vertical, 5).background(Theme.surface, in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))180 }181 }182 .padding(10)183 }184 .overlay(alignment: .topTrailing) { FavoriteButton(listing: listing, size: 36).padding(8) }185 }186187 private var confidence: String {188 switch listing.fvConfidence {189 case "haute": ", confiance élevée"190 case "moyenne": ", confiance moyenne"191 case "faible": ", confiance faible"192 default: ""193 }194 }195196 private var info: some View {197 VStack(alignment: .leading, spacing: 6) {198 HStack(alignment: .firstTextBaseline) {199 PriceText(price: listing.price, size: layout == .row ? 20 : 23)200 Spacer(minLength: 6)201 ScoreBadge(value: listing.scores.global)202 }203 HStack(spacing: 7) {204 if !listing.unitType.isEmpty {205 Text(listing.unitType).font(.caption.weight(.semibold)).foregroundStyle(Theme.ink)206 .padding(.horizontal, 6).padding(.vertical, 2.5)207 .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))208 }209 Text(listing.displayTitle).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink).lineLimit(1)210 }211 Text(listing.place).font(.footnote).foregroundStyle(Theme.ink3).lineLimit(1)212 ListingFacts(listing: listing)213 if let d = listing.plausibleDrop, let prev = listing.pricePrev {214 Label("Baisse de \(Fmt.pct(-d, signed: false)), était \(Fmt.money(prev))", systemImage: "arrow.down")215 .font(.caption.weight(.medium)).num().foregroundStyle(Theme.good).lineLimit(1)216 }217 if layout == .grid, let fv = listing.fv, let lo = listing.fvLow, let hi = listing.fvHigh {218 Text("Estimation ≈ \(Fmt.money(fv)), de \(Fmt.int(lo)) à \(Fmt.money(hi))\(confidence)")219 .font(.caption).num().foregroundStyle(Theme.ink3).lineLimit(2)220 }221 if layout == .grid {222 Divider().overlay(Theme.line).padding(.top, 4)223 HStack {224 Text(model.sourceName(listing.source)).lineLimit(1)225 Spacer()226 if let fs = listing.firstSeen { Text("vu \(Fmt.ago(fs))") }227 }228 .font(.caption2).foregroundStyle(Theme.ink3)229 }230 }231 .padding(layout == .row ? 12 : 14)232 }233234 private var grid: some View {235 VStack(spacing: 0) {236 // le cadre 4:3 fixe la hauteur ; la photo le remplit sans jamais l'agrandir237 Color.clear.aspectRatio(4 / 3, contentMode: .fit).frame(maxWidth: .infinity).overlay { photo }.clipped()238 info239 }240 }241242 private var row: some View {243 HStack(spacing: 0) {244 photo.frame(width: 132).frame(minHeight: 118).clipped()245 info.frame(maxWidth: .infinity, alignment: .leading)246 }247 .fixedSize(horizontal: false, vertical: true)248 }249}250251struct ListingCardSkeleton: View {252 var body: some View {253 VStack(alignment: .leading, spacing: 10) {254 Skeleton(height: 170, radius: 0)255 VStack(alignment: .leading, spacing: 9) {256 Skeleton(height: 22).frame(width: 110)257 Skeleton(height: 14).frame(maxWidth: 220)258 Skeleton(height: 12).frame(width: 130)259 }260 .padding(.horizontal, 14).padding(.bottom, 14)261 }262 .background(Theme.surface, in: RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))263 .overlay(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous).strokeBorder(Theme.line, lineWidth: 1))264 .clipShape(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))265 }266}267