//
//  PopoverViewController+initView.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/22.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

extension PopoverViewController {

    func addInitTableView() {
        dataSource = NSMutableArray()
        self.delegate = PopoverViewControllerDelegate()
        self.delegate.dataSource = self.dataSource
        self.myTableView.delegate = self.delegate
        self.myTableView.dataSource = self.delegate
        self.myTableView.separatorStyle = .none
        self.myTableView.backgroundColor = UIColor.white
        for index in 0..<popoverTypeArray.count {
            let popover = popoverTypeArray[index] as! PopoverType
            getPopoverTableViewCellModel(popoverType: popover)
        }
//        getPopoverTableViewCellModel()
    }
    func getPopoverTableViewCellModel(popoverType:PopoverType){
        let cellModel = PopoverTableViewCellModel()
        cellModel.className = "PopoverTableViewCell"
        cellModel.titleStr = getPopoverTypeTitle(popoverType: popoverType)
        cellModel.imageStr = getPopoverTypeImage(popoverType: popoverType)
        cellModel.block = {[weak self] in
            self?.popoverTypeblock(popoverType as AnyObject)
            self?.dismiss(animated: true, completion: nil)
        }
        self.dataSource.add(cellModel)
    }
    
    func getPopoverTypeTitle(popoverType:PopoverType) -> String {
        switch popoverType {
        case .ChangePassword:
            return "修改密码"
        case .DepartmentSwitching:
            return "部门切换"
        case .IntelligentCustomerService:
            return "智能客服"
        default:
            return "扫码追溯"
        }
    }
    func getPopoverTypeImage(popoverType:PopoverType) -> String {
        switch popoverType {
        case .ChangePassword:
            return "修改密码"
        case .DepartmentSwitching:
            return "switchDepartment_image"
        case .IntelligentCustomerService:
            return "customerService_image"
        default:
            return "scanCode_image"
        }
    }
}
class PopoverViewControllerDelegate: BaseOneTableViewDelegate {
    var cellNum:Double!
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        if (section==0){
            return 0
        }
        return 0
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 45
    }
}
