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

import UIKit
import WebKit
class TSBusinessWebVC: TSBaseVC , WKNavigationDelegate {
    
    enum UrlType:String {
        case privacy = "https://doc-hosting.flycricket.io/livelive-privacy-policy/10cde0be-3dae-4f7a-9e60-c5f92382ff21/privacy"
        case terms = "https://doc-hosting.flycricket.io/livelive-terms-of-use/7ec53e98-eb9d-49e0-b01d-bf315ba4384b/terms"

        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)
    }
    
}
