//
//  MineWebTableViewCell.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/12/18.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

class MineWebTableViewCell: BaseTableViewCell,WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler,UIScrollViewDelegate  {

    var xinfo:MineWebTableViewCellModel!
    lazy var webView: WKWebView = {
        let config = WKWebViewConfiguration.init()
        config.preferences = WKPreferences.init()
        config.preferences.minimumFontSize = 10;
        config.preferences.javaScriptEnabled = true
        config.preferences.javaScriptCanOpenWindowsAutomatically = true
        config.processPool = WKProcessPool.init()
        config.userContentController = WKUserContentController.init()
        let userContent = WKUserContentController.init()
        userContent.add(self as WKScriptMessageHandler, name: "AppLogout")
        config.userContentController = userContent
        let webView = WKWebView.init(frame: CGRect(x:0, y: 0, width:SCREEN_WHIDTH() , height:SCREEN_HEIGHT()), configuration: config)
        //webView.load(urlRequest as URLRequest)
        webView.isMultipleTouchEnabled = true
        webView.backgroundColor = UIColor.white
        webView.allowsBackForwardNavigationGestures = true
        webView.scrollView.isScrollEnabled = true
        webView.scrollView.bounces = true
        webView.uiDelegate = self
        webView.navigationDelegate = self
        webView.scrollView.delegate = self
        return webView
    }()
    private lazy var label: UILabel = {
        let label = UILabel(frame: CGRect(x:10, y: 0, width:self.width , height:20 ))
        //label.frame.origin.x = 20
        label.textColor = titleColor
        label.font = UIFont.systemFont(ofSize: 12)
        label.font = UIFont.boldSystemFont(ofSize: 12)
        //label.font = UIFont.init(name: "Arial Rounded MT Bold", size: 13)
        
        return label
    }()
    func setwebView(strUrl:String){
        webView.frame = CGRect(x:0, y: 20, width:SCREEN_WHIDTH() , height:self.height-20 )
        //print(strUrl)
        let url2:NSURL = NSURL.init(string: WebActionOC.share().getUrl(strUrl))!
        let urlRequest:NSURLRequest = NSURLRequest.init(url: url2 as URL)
        webView.load(urlRequest as URLRequest)
        
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.addSubview(label)
        self.addSubview(webView)
        // Initialization code
    }
    override func configurateTheCell(_ info: BaseCellModel) {
        let xinfo:MineWebTableViewCellModel = info as! MineWebTableViewCellModel
        //        self.block = xinfo.block
        self.label.text = xinfo.title
        self.setwebView(strUrl: xinfo.webUrl!)
        
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
class MineWebTableViewCellModel: BaseCellModel {
    
    var block:selectBlock!
    var webUrl:String?
    var webHeigh:CGFloat?
    var hightype:String?
    var title:String?
}
