Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Immo-Ka Admin iOS9// File : ImmoKaAdmin/Design/Components.swift10// Description : composants de base de l'outil — boutons, bandeau d'erreur,11// étiquette d'état, états vides, ligne « libellé … valeur »,12// formats de date. Sobre et dense : c'est un outil de13// travail.14// Module : ImmoKaAdmin15// Repository : https://git.spboucher.ai/immo-ka-admin-ios16// Project Website : https://www.immo-ka.com17// Created : 2026-11-3018// Last Modified : 2026-11-3019//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : None specified (no license file in this repository)85// Maintainer : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import SwiftUI93import UIKit9495struct PrimaryButtonStyle: ButtonStyle {96 var tint: Color = Theme.brand97 var foreground: Color = Theme.brandInk98 @Environment(\.isEnabled) private var enabled99 func makeBody(configuration: Configuration) -> some View {100 configuration.label101 .font(.body.weight(.semibold))102 .foregroundStyle(foreground)103 .padding(.horizontal, 20)104 .frame(minHeight: 50)105 .background(configuration.isPressed ? tint.opacity(0.8) : tint, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))106 .opacity(enabled ? 1 : 0.5)107 }108}109110struct SoftButtonStyle: ButtonStyle {111 @Environment(\.isEnabled) private var enabled112 func makeBody(configuration: Configuration) -> some View {113 configuration.label114 .font(.subheadline.weight(.semibold))115 .foregroundStyle(Theme.ink)116 .padding(.horizontal, 16)117 .frame(minHeight: 44)118 .background(configuration.isPressed ? Theme.surface3 : Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))119 .opacity(enabled ? 1 : 0.5)120 }121}122123/// Message d'erreur du serveur ou du réseau, lu par VoiceOver à son apparition.124struct ErrorBanner: View {125 let text: String126 var body: some View {127 Label { Text(verbatim: text) } icon: { Image(systemName: "exclamationmark.triangle") }128 .font(.subheadline)129 .foregroundStyle(Theme.bad)130 .fixedSize(horizontal: false, vertical: true)131 .padding(12)132 .frame(maxWidth: .infinity, alignment: .leading)133 .background(Theme.badSoft, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))134 .accessibilityIdentifier("error.banner")135 .onAppear { UIAccessibility.post(notification: .announcement, argument: text) }136 }137}138139/// Étiquette d'état : glyphe et libellé, jamais la couleur seule.140struct StatusTag: View {141 let label: String142 let symbol: String143 var tone: Tone = .neutral144 enum Tone { case neutral, good, warn, bad }145146 private var color: Color {147 switch tone {148 case .neutral: Theme.ink2149 case .good: Theme.brand150 case .warn: Theme.high151 case .bad: Theme.bad152 }153 }154 private var soft: Color {155 switch tone {156 case .neutral: Theme.surface2157 case .good: Theme.brandSoft158 case .warn: Theme.highSoft159 case .bad: Theme.badSoft160 }161 }162163 var body: some View {164 HStack(spacing: 4) {165 Image(systemName: symbol).font(.caption2.weight(.semibold))166 Text(label).font(.caption.weight(.semibold))167 }168 .foregroundStyle(color)169 .padding(.horizontal, 8).padding(.vertical, 4)170 .background(soft, in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))171 .fixedSize()172 .accessibilityElement(children: .ignore)173 .accessibilityLabel(label)174 }175}176177extension BrokerStatus {178 var tone: StatusTag.Tone {179 switch self {180 case .pending: .warn181 case .approved: .good182 case .refused, .suspended: .bad183 }184 }185 var tag: StatusTag { StatusTag(label: label, symbol: symbol, tone: tone) }186}187188struct EmptyState: View {189 var symbol = "tray"190 let title: String191 var message: String?192 var actionTitle: String?193 var action: (() -> Void)?194 var body: some View {195 VStack(spacing: 12) {196 Image(systemName: symbol).font(.system(size: 26, weight: .regular)).foregroundStyle(Theme.ink3).accessibilityHidden(true)197 Text(title).font(.editorial(20)).foregroundStyle(Theme.ink).multilineTextAlignment(.center)198 if let message { Text(verbatim: message).font(.subheadline).foregroundStyle(Theme.ink3).multilineTextAlignment(.center) }199 if let actionTitle, let action { Button(actionTitle, action: action).buttonStyle(SoftButtonStyle()).padding(.top, 4) }200 }201 .padding(28)202 .frame(maxWidth: 440)203 .frame(maxWidth: .infinity)204 }205}206207/// État de chargement, d'échec ou de contenu d'un écran.208struct Loadable<Value, Content: View>: View {209 let value: Value?210 let failure: String?211 var retry: () -> Void212 @ViewBuilder var content: (Value) -> Content213 var body: some View {214 if let value {215 content(value)216 } else if let failure {217 EmptyState(symbol: "wifi.exclamationmark", title: "Chargement impossible", message: failure, actionTitle: "Réessayer", action: retry)218 .frame(maxWidth: .infinity, maxHeight: .infinity)219 } else {220 ProgressView().frame(maxWidth: .infinity, maxHeight: .infinity)221 }222 }223}224225/// Ligne « libellé … valeur » ; la valeur est du texte brut, sélectionnable.226struct InfoRow: View {227 let label: String228 let value: String229 var body: some View {230 LabeledContent(label) { Text(verbatim: value).foregroundStyle(Theme.ink2).multilineTextAlignment(.trailing).textSelection(.enabled) }231 }232}233234/// Texte saisi par un tiers : brut, un paragraphe par ligne.235struct PlainText: View {236 let text: String237 var font: Font = .subheadline238 var color: Color = Theme.ink2239 var body: some View {240 Text(verbatim: text).font(font).foregroundStyle(color).lineSpacing(2).fixedSize(horizontal: false, vertical: true)241 .frame(maxWidth: .infinity, alignment: .leading).textSelection(.enabled)242 }243}244245enum Fmt {246 static let locale = Locale(identifier: "fr_CA")247 static func int(_ n: Int) -> String { n.formatted(.number.locale(locale).grouping(.automatic)) }248 static func plural(_ n: Int, _ one: String, _ many: String) -> String { "\(int(n)) \(n > 1 ? many : one)" }249250 /// Secondes depuis 1970 → « 30 nov. 2026, 14 h 05 ».251 static func dateTime(_ seconds: Double?) -> String {252 guard let seconds, seconds > 0 else { return "—" }253 return dateTime(Date(timeIntervalSince1970: seconds))254 }255 static func dateTime(_ date: Date) -> String {256 date.formatted(.dateTime.day().month(.abbreviated).year().hour().minute().locale(locale))257 }258 /// Date courte d'une liste : l'heure aujourd'hui, « hier », sinon le jour.259 static func short(_ date: Date?) -> String {260 guard let date else { return "" }261 if Calendar.current.isDateInToday(date) { return date.formatted(.dateTime.hour().minute().locale(locale)) }262 if Calendar.current.isDateInYesterday(date) { return "hier" }263 return date.formatted(.dateTime.day().month(.abbreviated).locale(locale))264 }265 static func relative(_ seconds: Double?) -> String {266 guard let seconds, seconds > 0 else { return "jamais" }267 return Date(timeIntervalSince1970: seconds).formatted(.relative(presentation: .named).locale(locale))268 }269}270271/// Seules les adresses http(s) s'ouvrent, dans Safari, hors de l'app.272func safeWebURL(_ string: String?) -> URL? {273 guard let string, let u = URL(string: string.trimmingCharacters(in: .whitespaces)), let scheme = u.scheme?.lowercased(), scheme == "http" || scheme == "https", u.host != nil else { return nil }274 return u275}276