//
//  BaseViewController+WebVC.swift
//  MobilePortal
//
//  Created by caiyang on 2020/8/26.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension BaseViewController {

    ///从web页面再次跳转
    func actionGotoWebGotoWeb(webViewUrl:String,isHomePushType:IsHomePushType,previousPageShowTitleType : IsShowTitleType) {
        let vc:WebSwiftViewController = WebSwiftViewController()
        vc.isHomePushType = isHomePushType
        vc.previousPageShowTitleType = previousPageShowTitleType
        vc.newType = .OrdinaryNewsType
        vc.isShowTitleType = self.getisShowTitleType(urlStr: webViewUrl)
        vc.webViewUrl = self.setisShowTitleType(urlStr: webViewUrl, isShowTitleType: vc.isShowTitleType)
        vc.hidesBottomBarWhenPushed = true
        self.pushViewController(viewController: vc, animated: true)
    }
    //跳转web页面
    func actionGotoTitleWeb(webViewUrl:String,title:String,isHomePushType:IsHomePushType,appid:String,isEncryptionType:IsEncryptionType) {
        self.gotoWebVC(title:title , webViewUrl: webViewUrl, newType: .WeiXinNewsType, isHomePushType: isHomePushType, isShowTitleType: self.getisShowTitleType(urlStr: webViewUrl), appid: appid, isEncryptionType: isEncryptionType)
    }
//    func actionGotoTitleWeb(webModel:WebUrlModel) {
//        webModel.newType = .WeiXinNewsType
//        webModel.isShowTitleType = self.getisShowTitleType(urlStr: webModel.webViewUrl)
//        self.gotoWebVC(webModel: webModel)
//    }
    func actionGotoWeb(webViewUrl:String,isHomePushType:IsHomePushType,isShowTitleType:IsShowTitleType,appid:String,isEncryptionType:IsEncryptionType) {
        if AccountInfo.sharedInstance().oldType == "0" {
            self.gotoWebVC(title:"" , webViewUrl: webViewUrl, newType: .OrdinaryNewsType, isHomePushType: isHomePushType, isShowTitleType: self.getisShowTitleType(urlStr: webViewUrl), appid: appid, isEncryptionType: isEncryptionType)
            return
        }
        self.gotoWebVC(title:"" , webViewUrl: webViewUrl, newType: .OrdinaryNewsType, isHomePushType: isHomePushType, isShowTitleType: isShowTitleType, appid: appid, isEncryptionType: isEncryptionType)
    }
//    func actionGotoWeb(webModel:WebUrlModel) {
//        webModel.newType = .OrdinaryNewsType
//        webModel.title = ""
//        webModel.isShowTitleType = self.getisShowTitleType(urlStr: webModel.webViewUrl)
//        self.gotoWebVC(webModel: webModel)
//    }
    func actionGotoMessageWeb(messageId:String?,isHomePushType:IsHomePushType) {
        let vc:WebSwiftViewController = WebSwiftViewController()
        vc.isHomePushType = isHomePushType
        vc.newType = .OrdinaryNewsType
        vc.isShowTitleType = .NoShowTitleType
        if AccountInfo.sharedInstance().UMS_messageType == "1" {
            // UMS 统一消息
            vc.isUMSMessageType = .IsUMSMessageType
            vc.appid = "ZYv36b9FG2YG3Eu0"
            vc.webViewUrl = AccountInfo.sharedInstance().UMS_messageDetaUrl
        } else {
            vc.isUMSMessageType = .NoUMSMessageType
            vc.webViewUrl = AccountInfo.sharedInstance().getMessageVCUrl()+messageId!+"&isOutUser="+judgmentStrNil(str: AccountInfo.sharedInstance().externalUser)
        }
        vc.encryptionContent = self.getEncryptionContentAction()
//        vc.webViewUrl = AccountInfo.sharedInstance().getMessageVCUrl()+messageId!
        vc.hidesBottomBarWhenPushed = true
        self.pushViewController(viewController: vc, animated: true)
    }
    func getEncryptionContentAction() -> String {
        let encryptionContent = "userId="+AccountInfo.sharedInstance().UserId!+"&loginType="+judgmentStrNil(str: AccountInfo.sharedInstance().loginType)+"&IDMToken="+judgmentStrNil(str: AccountInfo.sharedInstance().singlePoint_access_token)
        return encryptionContent
    }
    ///跳转web页面
    func gotoWebVC(title:String?,webViewUrl:String?,newType:NewType,isHomePushType:IsHomePushType,isShowTitleType:IsShowTitleType,appid:String,isEncryptionType:IsEncryptionType){
        let vc:WebSwiftViewController = WebSwiftViewController()
//        let vc:WebSwiftTwoViewController = WebSwiftTwoViewController()
        vc.title = title
        vc.isShowTitleType = isShowTitleType
        vc.newType = newType
        vc.appid = appid
        vc.isEncryptionType = isEncryptionType
        vc.isHomePushType = isHomePushType
        vc.webViewUrl = self.setisShowTitleType(urlStr: webViewUrl, isShowTitleType: isShowTitleType)
        vc.hidesBottomBarWhenPushed = true
        self.pushViewController(viewController: vc, animated: true)
    }
//    func gotoWebVC(webModel:WebUrlModel){
//        let vc:WebSwiftViewController = WebSwiftViewController()
//        vc.title = webModel.title
//        vc.isShowTitleType = webModel.isShowTitleType
//        vc.newType = webModel.newType
//        vc.isHomePushType = webModel.isHomePushType
//        vc.appid = webModel.appid
//        vc.isEncryptionType = webModel.isEncryptionType
//        vc.webViewUrl = self.setisShowTitleType(urlStr: webModel.webViewUrl, isShowTitleType: webModel.isShowTitleType)
//        vc.hidesBottomBarWhenPushed = true
//        self.pushViewController(viewController: vc, animated: true)
//    }
}
