//
//  LLQ_WebViewController.swift
//  SnapVPN
//
//  Created by FastKey on 2020/12/21.
//

import UIKit
import WebKit

class LLQ_WebViewController: LLQ_BaseViewController {

    enum Destination: String {

        case undefined = ""
        case terms = "Terms of Service"
        case policy = "Privacy Policy"

        var urlString: String {
            get {
                switch self {
                case .terms:
                    return LINK_TERMS
                case .policy:
                    return LINK_PRIVACY
                default:
                    return ""
                }
            }
        }
    }

    var destination: Destination = .undefined
    var destURLString: String? = nil
    var webView: WKWebView = WKWebView()

    override func viewDidLoad() {
        super.viewDidLoad()

        // set title
        title = destination.rawValue.localized()

        // webview
        webView.frame = view.bounds
        view.addSubview(webView)

        // get url string
        var urlString: String?
        switch destination {
        case .undefined:
            urlString = destURLString
        default:
            urlString = destination.urlString
        }
        // loadurl
        if let url = URL(string: urlString ?? "") {
//            LLQ_ScannerLog("[WEB] load: \(destination)")
            webView.load(URLRequest(url: url))
        } else {
//            LLQ_ScannerLog("[WEB] FAILED with load: \(destination)")
        }
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
}

