Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka iOS9// File : LouKa/Features/Messages/ManagerParts.swift10// Description : gestionnaires vérifiés — pastille « Gestionnaire vérifié11// », logo, bloc du gestionnaire dans la fiche d'un logement12// (mot du gestionnaire, « Écrire au gestionnaire »), fiche13// publique d'un gestionnaire, feuille de rédaction d'un14// message. Tout texte venu d'un gestionnaire est affiché tel15// quel (`Text(verbatim:)`) : ni Markdown, ni HTML, ni lien16// deviné.17// Module : LouKa18// Repository : https://git.spboucher.ai/lou-ka-ios-v319// Project Website : https://www.lou-ka.com20// Created : 2026-11-3021// Last Modified : 2026-11-3022//23// =============================================================================24// AUTHOR & PROFESSIONAL AFFILIATION25// =============================================================================26//27// Author : Simon-Pierre Boucher28// Position : Professor of Finance29// Institution : Université du Québec en Outaouais (UQO)30// Department : Département des sciences administratives31// Organization : SP Boucher32//33// Website : https://spboucher.ai34// Git : https://git.spboucher.ai35//36// =============================================================================37// OFFICIAL CONTACT DIRECTORY38// =============================================================================39//40// General : info@spboucher.ai41// Professional : contact@spboucher.ai42// Direct : simon@spboucher.ai43// Research : research@spboucher.ai44// Development : dev@spboucher.ai45// Support : support@spboucher.ai46// Security/Admin : admin@spboucher.ai47// Notifications : notifications@spboucher.ai48//49// Preferred Contact: support@spboucher.ai50//51// =============================================================================52// COPYRIGHT & INTELLECTUAL PROPERTY53// =============================================================================54//55// Copyright (c) 202656// Simon-Pierre Boucher57//58// All rights reserved where applicable.59//60// This file is governed by the applicable project license,61// copyright notices, institutional agreements and relevant law.62//63// Unless expressly authorized by the applicable license or64// rights holder, copying, redistribution, sublicensing,65// publication and commercial exploitation are not permitted.66//67// Existing third-party rights and notices remain unaffected.68//69// =============================================================================70// CONFIDENTIALITY & SECURITY71// =============================================================================72//73// Classification : Public74// Distribution : Public repository; use is governed by the project license75// Security Contact : admin@spboucher.ai76//77// Access to this source does not independently grant permission78// to redistribute or disclose confidential materials.79//80// Do not embed credentials, private keys, access tokens,81// certificates or confidential personal information.82//83// =============================================================================84// LICENSE & MAINTENANCE85// =============================================================================86//87// License : None specified (no license file in this repository)88// Maintainer : Simon-Pierre Boucher89// Technical Contact: dev@spboucher.ai90//91// =============================================================================92// END OF SP BOUCHER SOURCE HEADER93// =============================================================================9495import SwiftUI9697/// Pastille « Gestionnaire vérifié » : glyphe et libellé, jamais la couleur seule.98struct VerifiedBadge: View {99 var body: some View {100 HStack(spacing: 4) {101 Image(systemName: "checkmark.seal.fill").font(.system(size: 11, weight: .semibold))102 Text("Gestionnaire vérifié").font(.system(size: 12, weight: .semibold))103 }104 .foregroundStyle(Theme.brand)105 .padding(.horizontal, 8).padding(.vertical, 4)106 .background(Theme.brandSoft, in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))107 .fixedSize()108 .accessibilityElement(children: .ignore)109 .accessibilityLabel("Gestionnaire vérifié : l'équipe de Lou-Ka a validé que ce compte appartient à l'entreprise")110 .accessibilityIdentifier("manager.verified")111 }112}113114/// Logo d'un gestionnaire (image servie par Lou-Ka), ou son initiale.115struct ManagerLogo: View {116 let image: MediaImage?117 let name: String118 var size: CGFloat = 46119120 var body: some View {121 let shape = RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous)122 Group {123 if let src = image?.absolute(base: Account.baseURL()) {124 RemoteImage(source: src, contentMode: .fit).background(Theme.surface)125 } else {126 Text(verbatim: String(name.prefix(1)).uppercased()).font(.system(size: size * 0.42, weight: .semibold)).foregroundStyle(Theme.brand)127 .frame(maxWidth: .infinity, maxHeight: .infinity).background(Theme.brandSoft)128 }129 }130 .frame(width: size, height: size)131 .clipShape(shape)132 .overlay(shape.strokeBorder(Theme.line, lineWidth: 1))133 .accessibilityHidden(true)134 }135}136137/// Paragraphes d'un texte saisi par un tiers : texte brut, un paragraphe par ligne.138struct PlainParagraphs: View {139 let text: String140 var font: Font = .subheadline141 var color: Color = Theme.ink2142 var body: some View {143 VStack(alignment: .leading, spacing: 8) {144 ForEach(Array(ManagerFiche.paragraphs(text).enumerated()), id: \.offset) { _, p in145 Text(verbatim: p).font(font).foregroundStyle(color).lineSpacing(3).fixedSize(horizontal: false, vertical: true)146 }147 }148 .frame(maxWidth: .infinity, alignment: .leading)149 }150}151152// MARK: - Dans la fiche d'un logement153154/// Ce que le gestionnaire vérifié ajoute à « Publié par » : pastille, délai de réponse, mot, bouton d'écriture.155/// Rien n'est affiché tant que le serveur n'a pas répondu, ni si le gestionnaire n'est pas vérifié.156struct ListingManagerBlock: View {157 let listing: Listing158 let info: ListingManagerInfo159 @Environment(AppModel.self) private var app160 @Environment(Account.self) private var account161162 var body: some View {163 if let m = info.manager, m.verified {164 VStack(alignment: .leading, spacing: 12) {165 if let note = info.note {166 VStack(alignment: .leading, spacing: 6) {167 Label("Mot du gestionnaire", systemImage: "text.quote").font(.footnote.weight(.semibold)).foregroundStyle(Theme.ink2)168 PlainParagraphs(text: note, color: Theme.ink)169 }170 .padding(14)171 .frame(maxWidth: .infinity, alignment: .leading)172 .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))173 .accessibilityElement(children: .combine)174 .accessibilityIdentifier("manager.note")175 }176 if m.canMessage, account.user?.isManager != true {177 Button {178 app.compose = ComposeTarget(uid: listing.uid, sourceID: m.sourceID, managerName: m.name, listing: listing.snapshot)179 } label: {180 Label("Écrire au gestionnaire", systemImage: "bubble.left.and.text.bubble.right").frame(maxWidth: .infinity)181 }182 .buttonStyle(PrimaryButtonStyle())183 .accessibilityIdentifier("manager.write")184 if let r = m.responseTime {185 Text(verbatim: "Délai de réponse habituel : \(r)").font(.footnote).foregroundStyle(Theme.ink3)186 }187 }188 }189 }190 }191}192193// MARK: - Fiche publique d'un gestionnaire194195struct ManagerFicheView: View {196 let fiche: ManagerFiche197 let name: String198 @Binding var external: ExternalLink?199 @Environment(AppModel.self) private var app200 @Environment(Account.self) private var account201202 var body: some View {203 VStack(alignment: .leading, spacing: 22) {204 if let c = fiche.content {205 if let cover = c.cover?.absolute(base: Account.baseURL()) {206 RemoteImage(source: cover, width: .large)207 .aspectRatio(c.cover?.aspect ?? 2.5, contentMode: .fit)208 .clipShape(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))209 }210 if let t = c.tagline {211 Text(verbatim: t).font(.editorial(21)).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)212 .accessibilityIdentifier("manager.tagline")213 }214 }215 if fiche.canMessage, account.user?.isManager != true {216 VStack(alignment: .leading, spacing: 6) {217 Button { app.compose = ComposeTarget(uid: nil, sourceID: fiche.sourceID, managerName: name, listing: nil) } label: {218 Label("Écrire", systemImage: "bubble.left.and.text.bubble.right").frame(maxWidth: .infinity)219 }220 .buttonStyle(PrimaryButtonStyle())221 .accessibilityIdentifier("manager.write")222 if let r = fiche.content?.responseTime {223 Text(verbatim: "Délai de réponse habituel : \(r)").font(.footnote).foregroundStyle(Theme.ink3)224 }225 }226 }227 if let c = fiche.content { content(c) }228 }229 }230231 @ViewBuilder232 private func content(_ c: ManagerFiche.Content) -> some View {233 if c.about != nil || c.founded != nil || !c.languages.isEmpty {234 block("Présentation") {235 if let a = c.about { PlainParagraphs(text: a) }236 let facts = [c.founded.map { "Fondée en \($0)" }, c.languages.isEmpty ? nil : "Langues : " + c.languages.joined(separator: ", ")].compactMap { $0 }237 if !facts.isEmpty { Text(verbatim: facts.joined(separator: " · ")).font(.footnote).foregroundStyle(Theme.ink3) }238 }239 }240 if !c.highlights.isEmpty {241 LazyVGrid(columns: [GridItem(.adaptive(minimum: 130), spacing: 14, alignment: .topLeading)], alignment: .leading, spacing: 16) {242 ForEach(c.highlights) { h in243 VStack(alignment: .leading, spacing: 3) {244 Text(verbatim: h.text).font(.display(24)).num().foregroundStyle(Theme.ink).lineLimit(1).minimumScaleFactor(0.6)245 Text(verbatim: h.title).font(.footnote.weight(.medium)).foregroundStyle(Theme.ink2)246 }247 .frame(maxWidth: .infinity, alignment: .leading)248 .accessibilityElement(children: .combine)249 }250 }251 .cardStyle(padding: 16)252 }253 if !c.services.isEmpty {254 block("Services") {255 ForEach(c.services, id: \.self) { s in256 Label { Text(verbatim: s).foregroundStyle(Theme.ink2) } icon: { Image(systemName: "checkmark").foregroundStyle(Theme.brand) }257 .font(.subheadline)258 }259 }260 }261 if !c.policies.isEmpty {262 block("Politiques") {263 ForEach(c.policies) { p in264 VStack(alignment: .leading, spacing: 3) {265 Text(verbatim: p.title).font(.subheadline.weight(.semibold)).foregroundStyle(Theme.ink)266 PlainParagraphs(text: p.text)267 }268 }269 }270 }271 if !c.faq.isEmpty {272 block("Questions fréquentes") {273 ForEach(c.faq) { q in274 DisclosureGroup {275 PlainParagraphs(text: q.text).padding(.top, 6)276 } label: {277 Text(verbatim: q.title).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink).multilineTextAlignment(.leading)278 }279 .tint(Theme.ink3)280 }281 }282 }283 if !c.team.isEmpty {284 block("Équipe") {285 ForEach(c.team) { m in286 HStack(spacing: 12) {287 ManagerLogo(image: m.photo, name: m.name, size: 40)288 VStack(alignment: .leading, spacing: 1) {289 Text(verbatim: m.name).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)290 if let r = m.role { Text(verbatim: r).font(.footnote).foregroundStyle(Theme.ink3) }291 }292 }293 .accessibilityElement(children: .combine)294 }295 }296 }297 if !c.gallery.isEmpty {298 block("Galerie") {299 ScrollView(.horizontal, showsIndicators: false) {300 HStack(alignment: .top, spacing: 12) {301 ForEach(c.gallery) { p in302 VStack(alignment: .leading, spacing: 6) {303 RemoteImage(source: p.image.absolute(base: Account.baseURL()), width: .medium)304 .frame(width: 240, height: 160)305 .clipShape(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))306 if let cap = p.caption { Text(verbatim: cap).font(.caption).foregroundStyle(Theme.ink3).frame(width: 240, alignment: .leading) }307 }308 .accessibilityElement(children: .ignore)309 .accessibilityLabel(p.caption ?? "Photo de la galerie")310 }311 }312 }313 }314 }315 if c.phone != nil || c.email != nil || c.address != nil || !c.hours.isEmpty || ExternalLink(c.website) != nil || ExternalLink(c.bookingURL) != nil || !links(c).isEmpty {316 block("Coordonnées") {317 if let a = c.address { Label { Text(verbatim: a) } icon: { Image(systemName: "mappin.and.ellipse") }.font(.subheadline).foregroundStyle(Theme.ink2) }318 ForEach(c.hours) { h in319 HStack(alignment: .firstTextBaseline) {320 Text(verbatim: h.days).foregroundStyle(Theme.ink2)321 Spacer(minLength: 12)322 Text(verbatim: h.hours).foregroundStyle(Theme.ink).num()323 }324 .font(.subheadline)325 .accessibilityElement(children: .combine)326 }327 FlowLayout(spacing: 10) {328 if let p = c.phone, let tel = URL(string: "tel:\(p.filter { $0.isNumber || $0 == "+" })"), p.contains(where: \.isNumber) {329 Link(destination: tel) { Label { Text(verbatim: p) } icon: { Image(systemName: "phone") } }.buttonStyle(SoftButtonStyle())330 }331 if let e = c.email, Account.emailLooksValid(e), let mail = URL(string: "mailto:\(Account.clean(e))") {332 Link(destination: mail) { Label("Courriel", systemImage: "envelope") }.buttonStyle(SoftButtonStyle())333 }334 // un lien ne s'ouvre que s'il commence par http:// ou https:// (`ExternalLink`)335 if let l = ExternalLink(c.bookingURL) {336 Button { external = l } label: { Label("Prendre rendez-vous", systemImage: "calendar") }.buttonStyle(SoftButtonStyle())337 }338 if let l = ExternalLink(c.website) {339 Button { external = l } label: { Label("Site web", systemImage: "safari") }.buttonStyle(SoftButtonStyle())340 }341 ForEach(links(c)) { item in342 if let l = ExternalLink(item.url) {343 Button { external = l } label: { Text(verbatim: item.label) }.buttonStyle(SoftButtonStyle())344 }345 }346 }347 }348 }349 }350351 private func links(_ c: ManagerFiche.Content) -> [ManagerFiche.LinkItem] { c.social.filter { ExternalLink($0.url) != nil } }352353 private func block<C: View>(_ title: String, @ViewBuilder _ content: () -> C) -> some View {354 VStack(alignment: .leading, spacing: 12) {355 SectionHeader(title: title)356 content()357 }358 }359}360361// MARK: - Rédaction362363/// Feuille de rédaction d'un premier message. Sans compte : le texte est gardé en mémoire, on passe par la364/// connexion, puis la feuille revient avec le texte.365struct ComposeSheet: View {366 let target: ComposeTarget367 @Environment(\.dismiss) private var dismiss368 @Environment(AppModel.self) private var app369 @Environment(Account.self) private var account370 @State private var text = ""371 @State private var busy = false372 @State private var failure: String?373 @FocusState private var focused: Bool374375 private var count: Int { text.count }376377 var body: some View {378 NavigationStack {379 ScrollView {380 VStack(alignment: .leading, spacing: 16) {381 VStack(alignment: .leading, spacing: 4) {382 Text(verbatim: "À : \(target.managerName.isEmpty ? "Gestionnaire" : target.managerName)").font(.headline).foregroundStyle(Theme.ink)383 if let t = target.listingTitle {384 Text(verbatim: "À propos de : \(t)").font(.subheadline).foregroundStyle(Theme.ink2).lineLimit(2)385 }386 }387 if let failure { AccountBanner(text: failure) }388 VStack(alignment: .leading, spacing: 6) {389 TextEditor(text: $text)390 .focused($focused)391 .font(.body)392 .scrollContentBackground(.hidden)393 .frame(minHeight: 190)394 .padding(10)395 .background(Theme.surface, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))396 .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous).strokeBorder(Theme.lineControl, lineWidth: 1))397 .accessibilityLabel("Votre message")398 .accessibilityIdentifier("compose.text")399 .onChange(of: text) { _, v in if v.count > MessagingPolicy.maxLength { text = String(v.prefix(MessagingPolicy.maxLength)) } }400 Text("\(Fmt.int(count)) / \(Fmt.int(MessagingPolicy.maxLength)) caractères").font(.caption).num()401 .foregroundStyle(count >= MessagingPolicy.maxLength ? Theme.high : Theme.ink3)402 }403 AccountSubmit(title: account.isSignedIn ? "Envoyer" : "Se connecter pour envoyer", busy: busy,404 enabled: MessagingPolicy.clean(text) != nil, identifier: "compose.send", action: send)405 Text(account.user?.isPhoneAccount == true406 ? "Votre numéro n'est pas transmis au gestionnaire : la conversation se passe dans Lou-Ka. Sa réponse s'affichera dans l'application, sous Messages."407 : account.isSignedIn408 ? "Votre adresse courriel n'est pas transmise au gestionnaire : la conversation se passe dans Lou-Ka. Vous recevrez un avis par courriel quand il répondra."409 : "Un compte Lou-Ka est nécessaire pour écrire à un gestionnaire. Votre message est gardé le temps de vous connecter. Ni votre adresse courriel ni votre numéro ne sont transmis au gestionnaire.")410 .font(.footnote).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)411 }412 .padding(20)413 .frame(maxWidth: 560, alignment: .leading).frame(maxWidth: .infinity)414 }415 .scrollDismissesKeyboard(.interactively)416 .background(Theme.bg)417 .navigationTitle("Nouveau message")418 .navigationBarTitleDisplayMode(.inline)419 .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Annuler") { dismiss() }.accessibilityIdentifier("compose.cancel") } }420 }421 .tint(Theme.brand)422 .onAppear { if text.isEmpty { text = target.text ?? MessagingPolicy.prefill(listingTitle: target.listingTitle) } }423 }424425 private func send() {426 guard !busy, MessagingPolicy.clean(text) != nil else { return }427 guard account.isSignedIn else {428 // le texte attend en mémoire ; la feuille revient après la connexion (RootView)429 account.messaging.keepDraft(target, text: text)430 dismiss()431 app.accountSheet = true432 return433 }434 failure = nil; busy = true; focused = false435 Task {436 defer { busy = false }437 do {438 let t = try await account.messaging.open(target, text: text)439 Haptics.success()440 dismiss()441 app.showToast("Message envoyé")442 app.open(.conversation(t.conversation.id))443 } catch {444 failure = AccountFailure(error).message445 }446 }447 }448}449