//
//  TSBusinessWebVC.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/29.
//

import UIKit
import WebKit
class TSBusinessWebVC: TSBaseVC , WKNavigationDelegate {
    
    enum UrlType:String {
        case privacy = "http://100yearslater.com/Privacy.html"
        case terms = "http://100yearslater.com/Terms.html"

        func getTitle() -> String {
            switch self {
            case .privacy:
                return "Privacy Policy".localized
            case .terms:
                return "Terms Of Service".localized
            }
        }
    }
    
    private var webView: WKWebView!
    private var urlType: UrlType
    private var progressView: UIProgressView!
    
    init(urlType: UrlType) {
        self.urlType = urlType
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func createView() {
        addNormalNavBarView()
        setPageTitle(urlType.getTitle())
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupWebView()
        loadURL()
    }
    
    private func setupWebView() {
        // 初始化 WKWebView
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.navigationDelegate = self
        webView.translatesAutoresizingMaskIntoConstraints = false
        contentView.addSubview(webView)
        webView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

    }

    private func loadURL() {
        guard let url = URL(string: urlType.rawValue) else {
            debugPrint("无效的 URL")
            return
        }
        let request = URLRequest(url: url)
        webView.load(request)
    }
    
}
