// Auteur : Simon-Pierre Boucher — contact@spboucher.ai // Charge l'estimation complète d'une unité puis affiche EstimateView. import SwiftUI struct EstimateLoaderView: View { let searchResult: SearchResult @State private var data: UnitEstimate? @State private var errorMessage: String? var body: some View { Group { if let data { EstimateView(data: data) } else if let errorMessage { VStack(spacing: 14) { Text("!").font(.vpDisplay(40)).foregroundStyle(Color.vpLime) Text(errorMessage) .font(.vpBody(15)) .foregroundStyle(Color.vpInk2) .multilineTextAlignment(.center) Button("Réessayer") { self.errorMessage = nil Task { await load() } } .buttonStyle(VPGhostButtonStyle()) .frame(width: 180) } .padding(24) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.vpPaper) } else { VStack(spacing: 14) { ProgressView() .controlSize(.large) Text("Calcul de l'estimation…") .font(.vpMono(11)) .tracking(1.2) .foregroundStyle(Color.vpInk2) Text("Comparables + modèle hédonique") .font(.vpBody(13)) .foregroundStyle(Color.vpInk3) } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.vpPaper) .task { await load() } } } .navigationBarTitleDisplayMode(.inline) } private func load() async { do { data = try await VraiPrixAPI.shared.estimate(id: searchResult.id) } catch { errorMessage = error.localizedDescription } } }