SPB Git

Repository Public

AccountView.swift 31.8 KB 637 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Immo-Ka iOS9// File             : ImmoKa/Features/Account/AccountView.swift10// Description      : « Mon compte » — nom, courriel, synchronisation, mot de11//                    passe, appareils connectés, déconnexion, suppression du12//                    compte (mot de passe et confirmation). Lignes d'entrée du13//                    compte pour les Réglages et les Favoris.14// Module           : ImmoKa15// Repository       : https://git.spboucher.ai/immo-ka-ios-v316// 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 SwiftUI9394enum AccountSupport {95    static let email = "support@immo-ka.com"96    static var mailto: URL? { URL(string: "mailto:\(email)") }97}9899struct AccountView: View {100    @Environment(Account.self) private var account101    @Environment(AppModel.self) private var app102    @Environment(Library.self) private var library103    @Environment(\.dismiss) private var dismiss104105    @State private var name = ""106    @State private var savingName = false107    @State private var devices: [DeviceSession]?108    @State private var devicesError: String?109    @State private var failure: String?110    @State private var changingPassword = false111    @State private var deleting = false112    @State private var confirmSignOut = false113    @State private var confirmOthers = false114    @State private var busy = false115    #if DEBUG116    @State private var didAutoOpen = false117    #endif118119    var body: some View {120        Group {121            if let user = account.user {122                // comme les Réglages : fond de chaux et surfaces de l'app plutôt que le gris groupé du système123                form(user).scrollContentBackground(.hidden).background(Theme.bg).tint(Theme.brand)124            } else {125                // session fermée pendant que l'écran était ouvert126                EmptyStateView(door: .ajar, title: "Vous n'êtes pas connecté",127                               message: "Vos favoris restent sur cet appareil.",128                               actionTitle: "Se connecter") { dismiss(); app.accountSheet = true }129                    .frame(maxWidth: .infinity, maxHeight: .infinity).background(Theme.bg)130            }131        }132        .navigationTitle("Mon compte")133        .navigationBarTitleDisplayMode(.inline)134        .sheet(isPresented: $changingPassword) { ChangePasswordSheet() }135        .sheet(isPresented: $deleting) { DeleteAccountSheet { dismiss() } }136        .task {137            name = account.user?.name ?? ""138            await account.refresh()139            name = account.user?.name ?? name140            await loadDevices()141            #if DEBUG142            // -IKAccountPanel password|delete : ouvre une feuille au lancement (captures d'écran)143            if !didAutoOpen {144                didAutoOpen = true145                switch UserDefaults.standard.string(forKey: "IKAccountPanel") {146                case "password": changingPassword = true147                case "delete": deleting = true148                default: break149                }150            }151            #endif152        }153    }154155    private func form(_ user: AccountUser) -> some View {156        Form {157            if let failure {158                Section { Label(failure, systemImage: "exclamationmark.triangle").font(.subheadline).foregroundStyle(Theme.bad).accessibilityIdentifier("account.error") }159            }160            Section {161                HStack {162                    TextField("Nom", text: $name)163                        .textContentType(AutoFill.type(.name))164                        .textInputAutocapitalization(.words)165                        .submitLabel(.done)166                        .onSubmit(saveName)167                        .accessibilityLabel("Nom")168                        .accessibilityIdentifier("account.name")169                    if name.trimmingCharacters(in: .whitespaces) != user.name {170                        Button("Enregistrer", action: saveName).font(.subheadline.weight(.semibold)).disabled(savingName)171                            .accessibilityIdentifier("account.name.save")172                    }173                }174                if user.isPhoneAccount {175                    LabeledContent("Cellulaire") { Text(verbatim: user.contact).foregroundStyle(Theme.ink2).textSelection(.enabled) }176                        .accessibilityIdentifier("account.phone.value")177                } else if !user.contact.isEmpty {178                    LabeledContent("Courriel") { Text(verbatim: user.contact).foregroundStyle(Theme.ink2).textSelection(.enabled) }179                        .accessibilityIdentifier("account.email.value")180                }181            } header: {182                Text("Profil")183            } footer: {184                if user.isPhoneAccount {185                    Text("Ce compte est lié à votre numéro de cellulaire. Vous ne recevez pas de courriels d'Immo-Ka : les nouveaux messages s'affichent dans l'application.")186                        .accessibilityIdentifier("account.phone.note")187                }188            }189190            if let access = user.broker, user.isBroker { brokerSection(user, access) }191192            Section {193                NavigationLink(value: Route.messages) { MessagesEntryRow() }194                    .accessibilityIdentifier("account.messages")195            } footer: {196                Text(user.isBroker ? "Boîte partagée de votre accès de courtier : les messages des acheteurs."197                     : user.isPhoneAccount ? "Vos conversations avec les courtiers vérifiés. Votre numéro ne leur est jamais transmis."198                                           : "Vos conversations avec les courtiers vérifiés. Votre adresse courriel ne leur est jamais transmise.")199            }200201            if !user.isBroker {202            Section {203                LabeledContent("Favoris", value: Fmt.int(library.favoriteIDs.count))204                LabeledContent("Dernière synchronisation") {205                    if account.sync.syncing { ProgressView() } else {206                        Text(account.sync.lastSync.map { $0.formatted(.relative(presentation: .named).locale(Fmt.locale)) } ?? "pas encore")207                            .foregroundStyle(Theme.ink2)208                    }209                }210                if let e = account.sync.lastError {211                    Label(e, systemImage: "wifi.exclamationmark").font(.footnote).foregroundStyle(Theme.high)212                }213                Button("Synchroniser maintenant") { Task { await account.sync.sync() } }214                    .disabled(account.sync.syncing)215                    .accessibilityIdentifier("account.sync")216            } header: {217                Text("Synchronisation")218            } footer: {219                Text("Vos favoris, leurs notes et vos recherches enregistrées sont gardés dans votre compte et retrouvés sur le site et sur vos autres appareils. Le comparateur, l'historique de consultation et vos réglages restent sur cet appareil.")220            }221            }222223            Section("Sécurité") {224                Button { changingPassword = true } label: {225                    HStack { Label("Changer de mot de passe", systemImage: "key").foregroundStyle(Theme.ink); Spacer(); Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(Theme.ink3) }226                }227                .accessibilityIdentifier("account.changePassword")228            }229230            Section {231                if let devices {232                    ForEach(devices) { d in233                        HStack(spacing: 12) {234                            Image(systemName: d.client == "web" ? "globe" : d.client == "android" ? "candybarphone" : "iphone")235                                .foregroundStyle(Theme.ink2).frame(width: 26).accessibilityHidden(true)236                            VStack(alignment: .leading, spacing: 2) {237                                Text(d.current ? "\(d.clientLabel) · cet appareil" : d.clientLabel).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink)238                                Text(deviceCaption(d)).font(.caption).foregroundStyle(Theme.ink3)239                            }240                            Spacer()241                            if !d.current {242                                Button("Déconnecter") { revoke(d) }.font(.subheadline).buttonStyle(.borderless).disabled(busy)243                                    .accessibilityLabel("Déconnecter \(d.clientLabel)")244                            }245                        }246                        .accessibilityElement(children: .combine)247                    }248                    if devices.contains(where: { !$0.current }) {249                        Button("Déconnecter les autres appareils") { confirmOthers = true }250                            .disabled(busy)251                            .accessibilityIdentifier("account.signOutOthers")252                    }253                } else if let devicesError {254                    Label(devicesError, systemImage: "wifi.exclamationmark").font(.footnote).foregroundStyle(Theme.ink3)255                    Button("Réessayer") { Task { await loadDevices() } }256                } else {257                    ProgressView()258                }259            } header: {260                Text("Appareils connectés")261            }262            .confirmationDialog("Déconnecter les autres appareils ?", isPresented: $confirmOthers, titleVisibility: .visible) {263                Button("Déconnecter les autres", role: .destructive) { signOutOthers() }264                Button("Annuler", role: .cancel) {}265            } message: {266                Text("Seul cet appareil restera connecté à votre compte.")267            }268269            Section {270                Button("Se déconnecter") { confirmSignOut = true }271                    .disabled(busy)272                    .accessibilityIdentifier("account.signOut")273            } footer: {274                Text("Vos favoris, vos notes et vos recherches restent sur cet appareil après la déconnexion.")275            }276            .confirmationDialog("Se déconnecter ?", isPresented: $confirmSignOut, titleVisibility: .visible) {277                Button("Se déconnecter") { signOut() }.accessibilityIdentifier("account.signOut.confirm")278                Button("Annuler", role: .cancel) {}279            } message: {280                Text("Vos favoris restent sur cet appareil ; ils ne seront plus synchronisés.")281            }282283            Section {284                Button("Supprimer mon compte", role: .destructive) { deleting = true }285                    .accessibilityIdentifier("account.delete")286            } footer: {287                Text("Efface définitivement votre compte et tout ce qu'il contient sur nos serveurs. Besoin d'aide ? Écrivez à \(AccountSupport.email).")288            }289290            if let mail = AccountSupport.mailto {291                Section("Aide") {292                    Link(destination: mail) { Label(AccountSupport.email, systemImage: "envelope") }293                    NavigationLink(value: Route.privacy) { Label("Confidentialité", systemImage: "hand.raised") }294                }295            }296        }297    }298299    /// Compte de courtier : état de l'accès, motif transmis, renvoi vers le site pour le portail.300    @ViewBuilder301    private func brokerSection(_ user: AccountUser, _ access: BrokerAccess) -> some View {302        Section {303            if let company = access.company, !company.isEmpty {304                LabeledContent("Courtier") { Text(verbatim: company).foregroundStyle(Theme.ink2) }305            }306            if let agency = access.agency, !agency.isEmpty {307                LabeledContent("Agence") { Text(verbatim: agency).foregroundStyle(Theme.ink2) }308            }309            let state = access.state310            Label {311                Text(state == .approved ? "Accès approuvé" : state == .refused ? "Demande refusée" : state == .suspended ? "Accès suspendu" : "Demande en attente de validation")312                    .foregroundStyle(Theme.ink)313            } icon: {314                Image(systemName: state == .approved ? "checkmark.seal.fill" : state == .pending ? "hourglass" : "xmark.octagon")315                    .foregroundStyle(state == .approved ? Theme.brand : state == .pending ? Theme.high : Theme.bad)316            }317            .accessibilityIdentifier("account.broker.state")318            if state != .approved, let reason = access.reason, !reason.isEmpty {319                VStack(alignment: .leading, spacing: 3) {320                    Text("Motif transmis").font(.caption).foregroundStyle(Theme.ink3)321                    Text(verbatim: reason).font(.subheadline).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)322                }323                .accessibilityElement(children: .combine)324            }325            if let pro = URL(string: Account.baseURL().absoluteString.trimmingCharacters(in: CharacterSet(charactersIn: "/")) + "/pro") {326                Link(destination: pro) { Label("Ouvrir le portail sur le site", systemImage: "safari") }327            }328        } header: {329            Text("Accès de courtier")330        } footer: {331            Text(access.state == .pending ? "Votre adresse est confirmée. L'équipe d'Immo-Ka valide chaque demande à la main ; vous recevrez un courriel. L'éditeur de fiche, l'inventaire et le tableau de bord sont sur le site, à immo-ka.com/pro."332                 : access.state == .approved ? "L'éditeur de fiche, l'inventaire et le tableau de bord sont sur le site, à immo-ka.com/pro. Dans l'app, vous pouvez lire les messages reçus et y répondre."333                 : "Pour toute question sur cette décision : \(AccountSupport.email).")334        }335    }336337    private func deviceCaption(_ d: DeviceSession) -> String {338        var parts: [String] = []339        if let seen = d.seenAt ?? d.createdAt {340            parts.append("actif \(Date(timeIntervalSince1970: seen).formatted(.relative(presentation: .named).locale(Fmt.locale)))")341        }342        if let created = d.createdAt {343            parts.append("connecté le \(Date(timeIntervalSince1970: created).formatted(.dateTime.day().month().locale(Fmt.locale)))")344        }345        return parts.joined(separator: " · ")346    }347348    private func loadDevices() async {349        guard account.isSignedIn else { return }350        do { devices = try await account.devices(); devicesError = nil } catch {351            if devices == nil { devicesError = AccountFailure(error).message }352        }353    }354355    private func saveName() {356        guard let user = account.user, name.trimmingCharacters(in: .whitespaces) != user.name, !savingName else { return }357        savingName = true; failure = nil358        Task {359            defer { savingName = false }360            do { try await account.rename(name); name = account.user?.name ?? name; app.showToast("Nom enregistré") } catch { failure = AccountFailure(error).message }361        }362    }363364    private func revoke(_ d: DeviceSession) {365        busy = true; failure = nil366        Task {367            defer { busy = false }368            do { try await account.revoke(d); await loadDevices() } catch { failure = AccountFailure(error).message }369        }370    }371372    private func signOutOthers() {373        busy = true; failure = nil374        Task {375            defer { busy = false }376            do {377                let n = try await account.signOutEverywhereElse()378                app.showToast(n == 0 ? "Aucun autre appareil connecté" : Fmt.plural(n, "appareil déconnecté", "appareils déconnectés"))379                await loadDevices()380            } catch { failure = AccountFailure(error).message }381        }382    }383384    private func signOut() {385        busy = true386        Task {387            await account.signOut()388            busy = false389            app.showToast("Vous êtes déconnecté. Vos favoris restent sur cet appareil.")390            dismiss()391        }392    }393}394395// MARK: - Changer de mot de passe396397private struct ChangePasswordSheet: View {398    @Environment(Account.self) private var account399    @Environment(AppModel.self) private var app400    @Environment(\.dismiss) private var dismiss401    @State private var current = ""402    @State private var new = ""403    @State private var busy = false404    @State private var failure: AccountFailure?405406    var body: some View {407        NavigationStack {408            ScrollView {409                VStack(alignment: .leading, spacing: 20) {410                    Text("Vos autres appareils seront déconnectés ; celui-ci reste connecté.")411                        .font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)412                    if let m = failure?.general(fields: ["current_password", "new_password", "password"]) { AccountBanner(text: m) }413                    // courriel présent pour que le trousseau associe le nouveau mot de passe au bon compte414                    if let contact = account.user?.contact, !contact.isEmpty {415                        TextField("", text: .constant(contact)).textContentType(AutoFill.type(.username)).frame(width: 0, height: 0).opacity(0).accessibilityHidden(true)416                    }417                    PasswordInput(label: "Mot de passe actuel", text: $current, contentType: .password,418                                  error: failure?.on("current_password"), identifier: "account.currentPassword")419                    PasswordInput(label: "Nouveau mot de passe", text: $new, contentType: .newPassword, hint: "Au moins \(Account.passwordMin) caractères.",420                                  error: failure?.on("new_password") ?? failure?.on("password"), identifier: "account.newPassword", onSubmit: submit)421                    AccountSubmit(title: "Changer le mot de passe", busy: busy, enabled: !current.isEmpty && !new.isEmpty, action: submit)422                }423                .padding(24)424                .frame(maxWidth: 480, alignment: .leading).frame(maxWidth: .infinity)425            }426            .background(Theme.bg)427            .navigationTitle("Mot de passe")428            .navigationBarTitleDisplayMode(.inline)429            .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Annuler") { dismiss() } } }430        }431        .tint(Theme.brand)432    }433434    private func submit() {435        guard !busy else { return }436        guard new.count >= Account.passwordMin else {437            failure = AccountFailure(message: "Le mot de passe doit compter au moins \(Account.passwordMin) caractères.", param: "new_password"); return438        }439        failure = nil; busy = true440        Task {441            defer { busy = false }442            do {443                try await account.changePassword(current: current, new: new)444                dismiss()445                app.showToast("Mot de passe changé")446            } catch {447                var f = AccountFailure(error)448                if f.code == "mot_de_passe_incorrect" { f.param = "current_password" }449                failure = f450                if !account.isSignedIn { dismiss() }451            }452        }453    }454}455456// MARK: - Supprimer le compte457458private struct DeleteAccountSheet: View {459    var onDeleted: () -> Void460    @Environment(Account.self) private var account461    @Environment(AppModel.self) private var app462    @Environment(\.dismiss) private var dismiss463    @State private var password = ""464    @State private var busy = false465    @State private var confirm = false466    @State private var failure: AccountFailure?467468    var body: some View {469        NavigationStack {470            ScrollView {471                VStack(alignment: .leading, spacing: 20) {472                    VStack(alignment: .leading, spacing: 10) {473                        Text("Supprimer votre compte").font(.editorial(26)).foregroundStyle(Theme.ink).accessibilityAddTraits(.isHeader)474                        Text("La suppression est définitive et immédiate.").font(.subheadline.weight(.semibold)).foregroundStyle(Theme.ink)475                    }476                    VStack(alignment: .leading, spacing: 10) {477                        bullet("minus.circle", "Votre compte, votre courriel et votre nom sont effacés de nos serveurs.")478                        bullet("minus.circle", "Les favoris, notes et recherches gardés dans le compte sont effacés ; ils disparaîtront du site et de vos autres appareils connectés.")479                        bullet("iphone", "Ce qui se trouve sur cet appareil y reste : vous pourrez continuer d'utiliser Immo-Ka sans compte.")480                    }481                    .padding(14)482                    .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))483                    if let m = failure?.general(fields: ["password"]) { AccountBanner(text: m) }484                    PasswordInput(label: "Confirmez avec votre mot de passe", text: $password, contentType: .password,485                                  error: failure?.on("password"), identifier: "account.delete.password", onSubmit: { if !password.isEmpty { confirm = true } })486                    AccountSubmit(title: "Supprimer définitivement mon compte", busy: busy, enabled: !password.isEmpty, destructive: true,487                                  identifier: "account.delete.submit") { confirm = true }488                    Text("Mot de passe oublié ou besoin d'aide ? Écrivez à \(AccountSupport.email).")489                        .font(.footnote).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)490                }491                .padding(24)492                .frame(maxWidth: 480, alignment: .leading).frame(maxWidth: .infinity)493            }494            .background(Theme.bg)495            .navigationTitle("Suppression")496            .navigationBarTitleDisplayMode(.inline)497            .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Annuler") { dismiss() } } }498            .confirmationDialog("Supprimer votre compte pour de bon ?", isPresented: $confirm, titleVisibility: .visible) {499                Button("Supprimer mon compte", role: .destructive) { submit() }.accessibilityIdentifier("account.delete.confirm")500                Button("Annuler", role: .cancel) {}501            } message: {502                Text("Cette action ne peut pas être annulée.")503            }504        }505        .tint(Theme.brand)506    }507508    private func bullet(_ icon: String, _ text: String) -> some View {509        HStack(alignment: .firstTextBaseline, spacing: 10) {510            Image(systemName: icon).font(.footnote).foregroundStyle(Theme.ink3).frame(width: 18).accessibilityHidden(true)511            Text(text).font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)512        }513    }514515    private func submit() {516        guard !busy, !password.isEmpty else { return }517        failure = nil; busy = true518        Task {519            defer { busy = false }520            do {521                try await account.deleteAccount(password: password)522                dismiss()523                onDeleted()524                app.showToast("Compte supprimé. Vos favoris restent sur cet appareil.")525            } catch {526                var f = AccountFailure(error)527                if f.code == "mot_de_passe_incorrect" { f.param = "password" }528                failure = f529                if !account.isSignedIn { dismiss() }530            }531        }532    }533}534535// MARK: - Lignes d'entrée (Réglages, Favoris)536537/// Section « Compte » des Réglages : état du compte, ou invitation à se connecter.538struct AccountSettingsSection: View {539    @Environment(Account.self) private var account540    @Environment(AppModel.self) private var app541542    var body: some View {543        Section {544            if let user = account.user {545                NavigationLink(value: Route.account) {546                    HStack(spacing: 12) {547                        Image(systemName: "person.crop.circle").font(.title2).foregroundStyle(Theme.brand).accessibilityHidden(true)548                        VStack(alignment: .leading, spacing: 2) {549                            Text(user.displayName).font(.body.weight(.medium)).foregroundStyle(Theme.ink).lineLimit(1)550                            Text(verbatim: user.name.isEmpty || user.contact.isEmpty ? "Favoris synchronisés" : user.contact).font(.footnote).foregroundStyle(Theme.ink3).lineLimit(1)551                        }552                    }553                }554                .accessibilityIdentifier("settings.account")555                NavigationLink(value: Route.messages) { MessagesEntryRow() }556                    .accessibilityIdentifier("settings.messages")557            } else {558                Button { app.accountSheet = true } label: {559                    HStack(spacing: 12) {560                        Image(systemName: "person.crop.circle").font(.title2).foregroundStyle(Theme.brand).accessibilityHidden(true)561                        Text("Se connecter ou créer un compte").foregroundStyle(Theme.ink)562                        Spacer()563                        Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(Theme.ink3).accessibilityHidden(true)564                    }565                }566                .accessibilityIdentifier("settings.account")567            }568        } header: {569            Text("Compte")570        } footer: {571            Text(account.user?.isBroker == true ? "Compte de courtier : votre boîte de messages est ici ; le portail est sur le site."572                 : account.isSignedIn ? "Vos favoris, vos notes et vos recherches enregistrées sont synchronisés avec votre compte."573                                    : "Facultatif. Un compte sert à retrouver vos favoris, vos notes et vos recherches sur tous vos appareils.")574        }575    }576}577578/// Bas de l'onglet Favoris : invitation discrète quand on n'est pas connecté, état de la synchronisation sinon.579struct FavoritesAccountNote: View {580    @Environment(Account.self) private var account581    @Environment(AppModel.self) private var app582583    var body: some View {584        if let user = account.user {585            VStack(alignment: .leading, spacing: 10) {586                Button { app.open(.messages) } label: {587                    HStack(spacing: 8) {588                        MessagesEntryRow().font(.subheadline)589                        Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(Theme.ink3).accessibilityHidden(true)590                    }591                    .padding(.vertical, 12)592                    .contentShape(Rectangle())593                }594                .buttonStyle(.plain)595                .overlay(alignment: .top) { Divider().overlay(Theme.line) }596                .overlay(alignment: .bottom) { Divider().overlay(Theme.line) }597                .accessibilityIdentifier("favorites.messages")598                Button { app.open(.account) } label: {599                    Label {600                        Text(user.isBroker ? "Compte de courtier : vos favoris restent sur cet appareil."601                             : account.sync.lastError == nil ? "Synchronisés avec votre compte\(user.contact.isEmpty ? "" : " (\(user.contact))")."602                                                             : "Synchronisation en attente : elle reprendra au retour du réseau.")603                            .multilineTextAlignment(.leading)604                    } icon: {605                        Image(systemName: user.isBroker ? "building.2" : account.sync.lastError == nil ? "arrow.triangle.2.circlepath" : "wifi.exclamationmark")606                    }607                    .font(.caption).foregroundStyle(Theme.ink3)608                }609                .buttonStyle(.plain)610                .accessibilityHint("Ouvre Mon compte")611                .accessibilityIdentifier("favorites.account")612            }613        } else {614            VStack(alignment: .leading, spacing: 10) {615                Button { app.accountSheet = true } label: {616                    HStack(spacing: 12) {617                        Image(systemName: "person.crop.circle").font(.title3).foregroundStyle(Theme.brand).accessibilityHidden(true)618                        Text("Connectez-vous pour retrouver vos favoris sur tous vos appareils")619                            .font(.subheadline).foregroundStyle(Theme.ink).multilineTextAlignment(.leading)620                            .fixedSize(horizontal: false, vertical: true)621                        Spacer(minLength: 8)622                        Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(Theme.ink3).accessibilityHidden(true)623                    }624                    .padding(.vertical, 12)625                    .contentShape(Rectangle())626                }627                .buttonStyle(.plain)628                .overlay(alignment: .top) { Divider().overlay(Theme.line) }629                .overlay(alignment: .bottom) { Divider().overlay(Theme.line) }630                .accessibilityIdentifier("favorites.signIn")631                Label("Sans compte, rien ne quitte votre appareil : favoris, notes et recherches y sont enregistrés.", systemImage: "lock.shield")632                    .font(.caption).foregroundStyle(Theme.ink3)633            }634        }635    }636}637
Files main
Menu

Theme