Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : MacLustr Identity9// File : sdk/swift/Sources/MacLustrIdentityUI/StepViews.swift10// Module : MacLustrIdentityUI11// Repository : https://git.spboucher.ai/maclustr-identity12// Project Website : https://identity.spboucher.ai13// Created : 2026-12-0114// Last Modified : 2026-12-0115//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author : Simon-Pierre Boucher21// Position : Professor of Finance22// Institution : Université du Québec en Outaouais (UQO)23// Department : Département des sciences administratives24// Organization : SP Boucher25//26// Website : https://spboucher.ai27// Git : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General : info@spboucher.ai34// Professional : contact@spboucher.ai35// Direct : simon@spboucher.ai36// Research : research@spboucher.ai37// Development : dev@spboucher.ai38// Support : support@spboucher.ai39// Security/Admin : admin@spboucher.ai40// Notifications : notifications@spboucher.ai41//42// Preferred Contact: admin@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification : Public67// Distribution : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License : None specified (no license file in this repository)81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788// Screens of the flow that do not use the camera.89import SwiftUI90import MacLustrIdentityCore9192struct IntroStepView: View {93 @ObservedObject var flow: VerificationFlowModel94 @Environment(\.identityLanguage) private var lang9596 var body: some View {97 let selfie = flow.methods.contains { $0.requiresSelfie }98 StepLayout {99 Text(IdentityString.introTitle.text(lang)).font(.largeTitle.bold()).accessibilityAddTraits(.isHeader)100 Text(IdentityString.introBody.text(lang, flow.applicationName)).fixedSize(horizontal: false, vertical: true)101 VStack(alignment: .leading, spacing: 14) {102 row("doc.viewfinder", IdentityString.introStepDocument)103 if selfie { row("person.crop.circle", IdentityString.introStepSelfie) }104 row("checkmark.circle", IdentityString.introStepResult)105 }106 .padding(.vertical, 4)107 Text(IdentityString.introNeed.text(lang)).font(.callout).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)108 } actions: {109 Button(IdentityString.introStart.text(lang)) { flow.continueFromIntro() }.buttonStyle(PrimaryButtonStyle())110 }111 }112113 private func row(_ symbol: String, _ text: IdentityString) -> some View {114 HStack(alignment: .firstTextBaseline, spacing: 12) {115 Image(systemName: symbol).font(.title3).foregroundStyle(Color.accentColor).frame(width: 30).accessibilityHidden(true)116 Text(text.text(lang)).fixedSize(horizontal: false, vertical: true)117 }118 }119}120121struct MethodStepView: View {122 @ObservedObject var flow: VerificationFlowModel123 @Environment(\.identityLanguage) private var lang124125 /// The person came back here from a capture to pick another method.126 private var isChanging: Bool {127 flow.state?.status == .awaitingDocument || flow.state?.status == .awaitingSelfie128 }129130 var body: some View {131 StepLayout {132 Text(IdentityString.methodTitle.text(lang)).font(.title2.bold()).accessibilityAddTraits(.isHeader)133 if isChanging { NoticeView(kind: .info, text: IdentityString.changeMethodNotice.text(lang)) }134 ForEach(flow.methods) { method in135 // Sandbox sessions never capture images, so the camera does not matter there.136 let unavailable = method.requiresSelfie && !flow.isSandbox && !CameraController.hasCamera(.selfie)137 Button { flow.selectMethod(method.id) } label: {138 HStack(alignment: .center, spacing: 12) {139 VStack(alignment: .leading, spacing: 4) {140 Text(method.label[lang]).font(.headline).foregroundStyle(.primary).multilineTextAlignment(.leading)141 Text((unavailable ? IdentityString.methodNeedsCamera : method.biometric ? .methodBiometric : .methodNonBiometric).text(lang))142 .font(.subheadline).foregroundStyle(.secondary).multilineTextAlignment(.leading)143 }144 Spacer(minLength: 8)145 Image(systemName: "chevron.forward").foregroundStyle(.tertiary).accessibilityHidden(true)146 }147 .padding(16)148 .frame(maxWidth: .infinity, alignment: .leading)149 .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(Color.identityCard))150 .contentShape(Rectangle())151 }152 .buttonStyle(.plain)153 .accessibilityIdentifier("mlid.method." + method.id)154 .disabled(unavailable)155 .opacity(unavailable ? 0.5 : 1)156 }157 } actions: {158 if isChanging {159 Button(IdentityString.back.text(lang)) { flow.resumeCapture() }.buttonStyle(SecondaryButtonStyle())160 }161 }162 }163}164165/// Consent screen. The text comes from the service and is shown unchanged; the checkbox is never pre-ticked.166struct ConsentStepView: View {167 @ObservedObject var flow: VerificationFlowModel168 let methodID: String169 @Environment(\.identityLanguage) private var lang170 @Environment(\.openURL) private var openURL171 @State private var accepted = false172173 var body: some View {174 let method = flow.methods.first { $0.id == methodID }175 let text = method?.consentText(lang)176 StepLayout {177 Text(IdentityString.consentTitle.text(lang)).font(.title2.bold()).accessibilityAddTraits(.isHeader)178 if let text {179 Text(text.title).font(.headline)180 Text(text.body).fixedSize(horizontal: false, vertical: true)181 VStack(alignment: .leading, spacing: 10) {182 ForEach(Array(text.points.enumerated()), id: \.offset) { _, point in183 HStack(alignment: .firstTextBaseline, spacing: 8) {184 Text("•").accessibilityHidden(true)185 Text(point).font(.callout).fixedSize(horizontal: false, vertical: true)186 }187 }188 }189 if let controller = text.controller ?? flow.state?.controller {190 VStack(alignment: .leading, spacing: 4) {191 Text(IdentityString.consentController.text(lang, controller.name)).font(.footnote)192 if let contact = controller.contact { Text(contact).font(.footnote) }193 if let site = controller.site, let url = URL(string: site), url.scheme == "https" {194 Button(IdentityString.consentPrivacyPolicy.text(lang)) { openURL(url) }.buttonStyle(.plain).font(.footnote).foregroundStyle(Color.accentColor)195 }196 Text(IdentityString.consentVersion.text(lang, text.version)).font(.footnote)197 }198 .foregroundStyle(.secondary)199 }200 Toggle(isOn: $accepted) {201 Text(text.checkbox).font(.body.weight(.medium)).fixedSize(horizontal: false, vertical: true)202 }203 .toggleStyle(CheckboxRowStyle())204 .padding(14)205 .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(Color.identityCard))206 }207 if let error = flow.lastError { NoticeView(text: IdentityString.forError(error).text(lang)) }208 } actions: {209 Button(IdentityString.consentAccept.text(lang)) { Task { await flow.acceptConsent() } }210 .buttonStyle(PrimaryButtonStyle())211 .disabled(!accepted || flow.isBusy || text == nil)212 Button(IdentityString.consentDecline.text(lang)) { flow.declineConsent() }213 .buttonStyle(SecondaryButtonStyle())214 .disabled(flow.isBusy)215 }216 }217}218219/// A checkbox row that works the same on iOS and macOS, with the label read by VoiceOver.220struct CheckboxRowStyle: ToggleStyle {221 func makeBody(configuration: Configuration) -> some View {222 Button { configuration.isOn.toggle() } label: {223 HStack(alignment: .firstTextBaseline, spacing: 12) {224 Image(systemName: configuration.isOn ? "checkmark.square.fill" : "square")225 .font(.title3)226 .foregroundStyle(configuration.isOn ? Color.accentColor : Color.secondary)227 .accessibilityHidden(true)228 configuration.label.foregroundStyle(.primary).multilineTextAlignment(.leading)229 }230 .frame(maxWidth: .infinity, alignment: .leading)231 .contentShape(Rectangle())232 }233 .buttonStyle(.plain)234 .accessibilityIdentifier("mlid.consent.checkbox")235 .accessibilityAddTraits(configuration.isOn ? [.isSelected] : [])236 }237}238239struct SandboxStepView: View {240 @ObservedObject var flow: VerificationFlowModel241 @Environment(\.identityLanguage) private var lang242243 var body: some View {244 StepLayout {245 Text(IdentityString.sandboxTitle.text(lang)).font(.title2.bold()).accessibilityAddTraits(.isHeader)246 Text(IdentityString.sandboxBody.text(lang)).fixedSize(horizontal: false, vertical: true)247 if let error = flow.lastError { NoticeView(text: IdentityString.forError(error).text(lang)) }248 ForEach(flow.state?.sandbox?.scenarios ?? []) { scenario in249 Button(scenario.label[lang]) { Task { await flow.runSandboxScenario(scenario.id) } }250 .buttonStyle(SecondaryButtonStyle())251 .disabled(flow.isBusy)252 }253 } actions: { EmptyView() }254 }255}256257struct ProgressStepView: View {258 @ObservedObject var flow: VerificationFlowModel259 let submitting: Bool260 let onClose: () -> Void261 @Environment(\.identityLanguage) private var lang262263 var body: some View {264 StepLayout {265 VStack(spacing: 16) {266 ProgressView().controlSize(.large).padding(.top, 40)267 Text((submitting ? IdentityString.submitting : .processingTitle).text(lang)).font(.title2.bold()).accessibilityAddTraits(.isHeader)268 if !submitting {269 Text(flow.processingIsSlow ? IdentityString.processingSlow.text(lang, flow.applicationName) : IdentityString.processingBody.text(lang))270 .multilineTextAlignment(.center)271 .foregroundStyle(.secondary)272 .fixedSize(horizontal: false, vertical: true)273 }274 if let error = flow.lastError { NoticeView(text: IdentityString.forError(error).text(lang)) }275 }276 .frame(maxWidth: .infinity)277 } actions: {278 if flow.processingIsSlow, !submitting {279 Button(IdentityString.finishLater.text(lang), action: onClose).buttonStyle(SecondaryButtonStyle())280 }281 }282 }283}284285struct ResultStepView: View {286 @ObservedObject var flow: VerificationFlowModel287 let status: SessionStatus288 let onClose: () -> Void289 @Environment(\.identityLanguage) private var lang290 @State private var showDispute = false291 @State private var confirmWithdraw = false292293 private var presentation: (symbol: String, color: Color, title: IdentityString, body: String) {294 let app = flow.applicationName295 switch status {296 case .verified: return ("checkmark.circle", .green, .resultVerifiedTitle, IdentityString.resultVerifiedBody.text(lang, app))297 case .manualReview: return ("person.crop.circle.badge.clock", .accentColor, .resultReviewTitle, IdentityString.resultReviewBody.text(lang, app))298 case .inconclusive: return ("questionmark.circle", .orange, .resultInconclusiveTitle, IdentityString.resultInconclusiveBody.text(lang, app))299 case .rejected: return ("xmark.circle", .red, .resultRejectedTitle, IdentityString.resultRejectedBody.text(lang))300 case .expired: return ("clock", .secondary, .resultExpiredTitle, IdentityString.resultExpiredBody.text(lang, app))301 case .cancelled: return ("trash.circle", .secondary, .resultCancelledTitle, IdentityString.resultCancelledBody.text(lang))302 case .revoked: return ("xmark.circle", .secondary, .resultRevokedTitle, IdentityString.resultRevokedBody.text(lang, app))303 default: return ("circle", .secondary, .resultUnknownTitle, "")304 }305 }306307 var body: some View {308 let p = presentation309 // The simulated-result marker of the sandbox is shown through the sandbox badge, not as a reason.310 let reasons = (flow.state?.result?.reasons ?? []).filter { status != .verified || $0.code != "simulated" }311 StepLayout {312 VStack(spacing: 14) {313 Image(systemName: p.symbol).font(.system(size: 56, weight: .regular)).foregroundStyle(p.color).padding(.top, 28).accessibilityHidden(true)314 Text(p.title.text(lang)).font(.title.bold()).multilineTextAlignment(.center).accessibilityAddTraits(.isHeader)315 if !p.body.isEmpty {316 Text(p.body).multilineTextAlignment(.center).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)317 }318 }319 .frame(maxWidth: .infinity)320 if !reasons.isEmpty, status != .cancelled, status != .expired {321 VStack(alignment: .leading, spacing: 8) {322 Text(IdentityString.resultReasons.text(lang)).font(.headline)323 ForEach(reasons, id: \.code) { reason in324 Text(reason.message[lang]).font(.callout).fixedSize(horizontal: false, vertical: true)325 }326 }327 .padding(14)328 .frame(maxWidth: .infinity, alignment: .leading)329 .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(Color.identityCard))330 }331 if flow.disputeSent { NoticeView(kind: .info, text: IdentityString.disputeSent.text(lang)) }332 } actions: {333 Button(IdentityString.done.text(lang), action: onClose).buttonStyle(PrimaryButtonStyle())334 if flow.canDispute {335 Button(IdentityString.resultDispute.text(lang)) { showDispute = true }.buttonStyle(SecondaryButtonStyle())336 }337 // While a person reviews the file, consent can still be withdrawn. Destructive: always confirmed first.338 if status == .manualReview, flow.canWithdraw {339 Button(IdentityString.withdrawAction.text(lang), role: .destructive) { confirmWithdraw = true }340 .buttonStyle(SecondaryButtonStyle())341 .accessibilityIdentifier("mlid.withdraw")342 }343 }344 .confirmationDialog(IdentityString.withdrawConfirmTitle.text(lang), isPresented: $confirmWithdraw, titleVisibility: .visible) {345 Button(IdentityString.withdrawConfirm.text(lang), role: .destructive) { Task { await flow.withdraw() } }346 Button(IdentityString.cancel.text(lang), role: .cancel) {}347 } message: {348 Text(IdentityString.withdrawConfirmBody.text(lang))349 }350 .sheet(isPresented: $showDispute) { DisputeSheet(flow: flow, isPresented: $showDispute).environment(\.identityLanguage, lang) }351 .onAppear { Accessibility.announce(p.title.text(lang)) }352 }353}354355struct DisputeSheet: View {356 @ObservedObject var flow: VerificationFlowModel357 @Binding var isPresented: Bool358 @Environment(\.identityLanguage) private var lang359 @State private var message = ""360361 var body: some View {362 let length = message.trimmingCharacters(in: .whitespacesAndNewlines).count363 StepLayout {364 Text(IdentityString.disputeTitle.text(lang)).font(.title2.bold()).accessibilityAddTraits(.isHeader)365 Text(IdentityString.disputePlaceholder.text(lang)).font(.callout).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)366 TextEditor(text: $message)367 .frame(minHeight: 160)368 .padding(8)369 .overlay(RoundedRectangle(cornerRadius: 10, style: .continuous).strokeBorder(Color.secondary.opacity(0.4)))370 .accessibilityLabel(IdentityString.disputeTitle.text(lang))371 if let error = flow.lastError { NoticeView(text: IdentityString.forError(error).text(lang)) }372 } actions: {373 Button(IdentityString.disputeSend.text(lang)) {374 Task { if await flow.dispute(message: message) { isPresented = false } }375 }376 .buttonStyle(PrimaryButtonStyle())377 .disabled(length < 5 || length > 2000 || flow.isBusy)378 Button(IdentityString.cancel.text(lang)) { isPresented = false }.buttonStyle(SecondaryButtonStyle())379 }380 #if os(macOS)381 .frame(minWidth: 420, minHeight: 420)382 #endif383 }384}385386struct FailedStepView: View {387 @ObservedObject var flow: VerificationFlowModel388 let error: IdentityError389 let onClose: () -> Void390 @Environment(\.identityLanguage) private var lang391392 var body: some View {393 StepLayout {394 VStack(spacing: 14) {395 Image(systemName: "exclamationmark.triangle").font(.system(size: 48)).foregroundStyle(.orange).padding(.top, 28).accessibilityHidden(true)396 Text(IdentityString.forError(error).text(lang)).font(.title3.weight(.semibold)).multilineTextAlignment(.center).fixedSize(horizontal: false, vertical: true)397 if case .api(let e) = error, let id = e.requestID {398 Text(id).font(.footnote.monospaced()).foregroundStyle(.secondary).textSelection(.enabled)399 }400 }401 .frame(maxWidth: .infinity)402 } actions: {403 if error.isRetryable {404 Button(IdentityString.retry.text(lang)) { Task { await flow.start() } }.buttonStyle(PrimaryButtonStyle())405 }406 Button(IdentityString.close.text(lang), action: onClose).buttonStyle(SecondaryButtonStyle())407 }408 }409}410