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

import UIKit

extension SelectCompanyViewController {

    func addInitTableView() {
        if #available(iOS 11.0, *) {
            self.companyTableView.contentInsetAdjustmentBehavior = .never
            self.companyTableView.scrollIndicatorInsets = self.companyTableView.contentInset
            self.companyTableView.contentInset = UIEdgeInsetsMake(UIApplication.shared.statusBarFrame.size.height+44, 0, 0, 0)
        }else{
            self.companyTableView.contentInset = UIEdgeInsetsMake(0, 0, HEIGHT_BOTTOM_MARGIN(), 0)
        }
        self.dataSource = NSMutableArray()
        //initdataSource(array: self.dataSource)
        
        
        self.companyTableView.showsVerticalScrollIndicator = false
        rightComanyLayoutConstraint.constant = SCREEN_WHIDTH()/2
        registerCell(self.companyTableView, cell: CompanyListTableViewCell.self)
        self.delegate = SelectCompanyViewControllerDelegate()
        self.delegate.dataSource = self.dataSource
        self.companyTableView.delegate = self.delegate
        self.companyTableView.dataSource = self.delegate
        self.companyTableView.backgroundColor = grayBgColor
        setExtraCellLineHidden(tableView: self.companyTableView)
    }
    func addInitdepartmentTableView() {
        if #available(iOS 11.0, *) {
            self.departmentTableView.contentInsetAdjustmentBehavior = .never
            self.departmentTableView.scrollIndicatorInsets = self.departmentTableView.contentInset
        }
        self.depDataSource = NSMutableArray()
        //initdataSource(array: self.depDataSource)
        self.departmentTableView.contentInset = UIEdgeInsetsMake(UIApplication.shared.statusBarFrame.size.height+44, 0, 0, 0)
        self.departmentTableView.showsVerticalScrollIndicator = false
        leftDepartmentLayoutConstraint.constant = SCREEN_WHIDTH()/2
        registerCell(self.departmentTableView, cell: CompanyListTableViewCell.self)
        self.depDelegate = SelectCompanyViewControllerDelegate()
        self.depDelegate.dataSource = self.depDataSource
        self.departmentTableView.delegate = self.depDelegate
        self.departmentTableView.dataSource = self.depDelegate
        self.departmentTableView.backgroundColor = grayBgColor
        setExtraCellLineHidden(tableView: self.departmentTableView)
    }
}
class SelectCompanyViewControllerDelegate: 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 tableViewSectionZero(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell{
        
        let info:CompanyListTableViewCellModel = self.dataSource.object(at: indexPath.row) as! CompanyListTableViewCellModel
        let cellClass = swiftClassFromString(info.className) as! BaseTableViewCell.Type
        let cell = getCell(tableView, cell: cellClass.self, indexPath: indexPath as IndexPath)
        cell.configurateTheCell(info)
        return cell
    }
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let info:CompanyListTableViewCellModel = self.dataSource.object(at: indexPath.row) as! CompanyListTableViewCellModel
        let h = getTextHeigh(textStr: info.titleValue!, font: UIFont.systemFont(ofSize: 16*WHIDTH_RATIO()), width: SCREEN_WHIDTH()/2)
        if h > 44{
            return h
        }
        return 44
    }
}
