import SwiftUI import WebKit private struct RemotePDFView: View { let url: URL @Binding var isLoading: Bool @Binding var hasError: Bool var body: some View { RemotePDFRepresentable(url: url, isLoading: $isLoading, hasError: $hasError) } } #if canImport(UIKit) private struct RemotePDFRepresentable: UIViewRepresentable { let url: URL @Binding var isLoading: Bool @Binding var hasError: Bool func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() webView.navigationDelegate = context.coordinator webView.load(URLRequest(url: url)) return webView } func updateUIView(_ uiView: WKWebView, context: Context) {} func makeCoordinator() -> RemotePDFCoordinator { RemotePDFCoordinator(isLoading: $isLoading, hasError: $hasError) } } #elseif canImport(AppKit) private struct RemotePDFRepresentable: NSViewRepresentable { let url: URL @Binding var isLoading: Bool @Binding var hasError: Bool func makeNSView(context: Context) -> WKWebView { let webView = WKWebView() webView.navigationDelegate = context.coordinator webView.load(URLRequest(url: url)) return webView } func updateNSView(_ nsView: WKWebView, context: Context) {} func makeCoordinator() -> RemotePDFCoordinator { RemotePDFCoordinator(isLoading: $isLoading, hasError: $hasError) } } #endif private final class RemotePDFCoordinator: NSObject, WKNavigationDelegate { @Binding var isLoading: Bool @Binding var hasError: Bool init(isLoading: Binding, hasError: Binding) { self._isLoading = isLoading self._hasError = hasError } func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { isLoading = true hasError = false } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { isLoading = false } func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { isLoading = false hasError = true } func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { isLoading = false hasError = true } } private struct LegalDocumentScreen: View { let title: String let headerTitle: String let document: LegalDocument @Environment(\.colorScheme) var colorScheme @Environment(\.dismiss) var dismiss @State private var isLoading = true @State private var hasError = false var body: some View { VStack(spacing: 0) { screenHeader .padding(24) ZStack { RemotePDFView(url: document.url, isLoading: $isLoading, hasError: $hasError) if isLoading { ProgressView() } if hasError { VStack(spacing: 8) { Text("Não foi possível carregar \(title.lowercased()).") .font(AppTypography.body) .foregroundStyle(AppColors.textPrimary) .multilineTextAlignment(.center) } .padding(24) } } } .background((colorScheme == .dark ? Color.black : AppColors.backgroundLight).ignoresSafeArea()) .appHiddenNavigationBar() .navigationBarBackButtonHidden(true) } private var screenHeader: some View { ZStack { Text(headerTitle) .font(AppTypography.heading2) .foregroundStyle(AppColors.textPrimary) HStack { Button(action: { dismiss() }) { Image(systemName: "chevron.left") .font(.system(size: 24, weight: .semibold)) .foregroundStyle(AppColors.textPrimary) .frame(width: 52, height: 52) .background(AppColors.surface) .clipShape(Circle()) .shadow(color: .black.opacity(0.06), radius: 8, y: 2) } .buttonStyle(.plain) Spacer() } } } } struct TermsOfUseView: View { var body: some View { LegalDocumentScreen(title: "os Termos de Uso", headerTitle: "Termos de Uso", document: .terms) } } struct PrivacyPolicyView: View { var body: some View { LegalDocumentScreen(title: "a Política de Privacidade", headerTitle: "Privacidade", document: .privacyPolicy) } }