//
//  MineViewController+PopoverView.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/25.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

extension MineViewController {

//    @objc func shouwPopover(){
//        let vc:PopoverViewController = PopoverViewController()
//        vc.popoverTypeblock = {[weak self] (value:Any) in
//            self?.popoActionGotoVC(popoverType: value as! PopoverType)
//        }
//        vc.popoverTypeArray = getPopoverTypeArray()
//        vc.preferredContentSize = CGSize(width: 115, height: vc.popoverTypeArray.count*45)
//        vc.modalPresentationStyle = .popover
//        let povc:UIPopoverPresentationController = vc.popoverPresentationController!
//        povc.barButtonItem = self.navigationItem.rightBarButtonItem
//        povc.delegate = self
//        self.present(vc, animated: true, completion: nil)
//        self.tabBarController?.present(vc, animated: true, completion: nil)
//    }
    func popoActionGotoVC(popoverType:PopoverType){
        switch popoverType {
//        case .ChangePassword:
//        self.mineGotoChangePassWordViewController(changePassWordType: .OrdinaryChangePassWordType)
//            break
        case .DepartmentSwitching:
            self.gotoSetVC()
            break
        case .IntelligentCustomerService:
            actionCustomerServiceVC()
            break
        default:
            self.gotoQRCodeSwiftViewController(isHomePushType: .YesIsHomePushType)
            break
        }
    }
    ///跳转 部门选择
    func gotoSetVC(){
        let vc:SetCompanyDepartmentViewController=SetCompanyDepartmentViewController()
        vc.hidesBottomBarWhenPushed = true
//        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
            self.pushViewController(viewController: vc, animated: true)
//        }
    }
    
    func getPopoverTypeArray() -> NSMutableArray {
        let array = NSMutableArray()
        if AccountInfo.sharedInstance().infoCompanyName == "上药控股有限公司" {
            array.add(PopoverType.ScanCodeTraceability)
        }
        array.add(PopoverType.IntelligentCustomerService)
        array.add(PopoverType.ChangePassword)
        if getAllSelecCompanyDepartment().count != 0 {
            array.add(PopoverType.DepartmentSwitching)
        }
        return array
    }
    func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        hideNavigationBar()
        return UIModalPresentationStyle.none
    }
    @objc func shouwPopover(){
        let popOption = FKGPopOption.init(frame: CGRect(x:0, y: 0, width:SCREEN_WHIDTH() , height:SCREEN_HEIGHT() ))
        self.getArray(popOption: popOption)
        popOption.option_lineHeight = 45
        popOption.option_mutiple = 115/360
        popOption.option_setupPopOption({[weak self] (index, content) in
            if (content == "扫码追溯") {
                self?.gotoQRCodeSwiftViewController(isHomePushType: .YesIsHomePushType)
            } else if (content == "智能客服") {
//                self?.actionCustomerServiceVC()
                self?.getApplicationByBelongAction(applicationName: "IT_ROBOT")
            } else if (content == "部门切换") {
                self?.gotoSetVC()
            } else if (content == "修改密码") {
                self?.mineGotoChangePassWordViewController(changePassWordType: .OrdinaryChangePassWordType)
            }
        }, whichFrame: CGRect(x:SCREEN_WHIDTH()-128, y: STATUBAR_HEIGHT()-10, width:115 , height:45 ), animate: true)?.option_show()
    }
    func getArray(popOption: FKGPopOption) {
        let titleArray = NSMutableArray()
        let imageArray = NSMutableArray()
        if AccountInfo.sharedInstance().infoCompanyName == "上药控股有限公司" {
            titleArray.add("扫码追溯")
            imageArray.add("scanCode_image")
        }
        titleArray.add("智能客服")
        imageArray.add("customerService_image")
        titleArray.add("修改密码")
        imageArray.add("password_image")
        if getAllSelecCompanyDepartment().count != 0 {
            titleArray.add("部门切换")
            imageArray.add("switchDepartment_image")
        }
        popOption.option_optionContents = (titleArray as! [Any])
        popOption.option_optionImages = (imageArray as! [Any])

    }
}
