//
//  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.createViewController(createArgs: nil) as! PopoverViewController
        vc.popoverTypeblock = {[weak self] (value:Any) in
            self?.popoActionGotoVC(popoverType: value as! PopoverType)
        }
        vc.popoverTypeArray = getPopoverTypeArray()
        vc.preferredContentSize = CGSize(width: 100, height: vc.popoverTypeArray.count*40)
        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 {
        
        return UIModalPresentationStyle.none
    }
}
