import SwiftUI
import WebKit

struct PrivacyPolicyView: View {
    @EnvironmentObject private var languageManager: LanguageManager
    
    var body: some View {
        ZStack {
            // 背景渐变
            LinearGradient(
                gradient: Gradient(colors: [
                    Color(.systemBackground),
                    Color(.systemGray6).opacity(0.2)
                ]),
                startPoint: .top,
                endPoint: .bottom
            )
            .ignoresSafeArea()
            
            // WebView显示HTML隐私政策
            WebView(url: Bundle.main.url(forResource: "privacy_policy", withExtension: "html")!)
                .ignoresSafeArea(.container, edges: .bottom)
        }
        .navigationTitle("privacy_policy".localized)
        .navigationBarTitleDisplayMode(.inline)
        .navigationBarBackButtonHidden(false)
    }
}

// MARK: - WebView
struct WebView: UIViewRepresentable {
    let url: URL
    
    func makeUIView(context: Context) -> WKWebView {
        let webView = WKWebView()
        webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
        webView.scrollView.contentInsetAdjustmentBehavior = .never
        webView.scrollView.showsVerticalScrollIndicator = true
        webView.scrollView.showsHorizontalScrollIndicator = false
        return webView
    }
    
    func updateUIView(_ uiView: WKWebView, context: Context) {
        // 不需要更新
    }
}

#Preview {
    NavigationView {
        PrivacyPolicyView()
            .environmentObject(LanguageManager.shared)
    }
}
