//
//  UpcomingViewController+initView.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2020/2/10.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension UpcomingViewController {
    
    
    func addTitleView(){
        self.view.addSubview(tixingImage)
        tixingLabel.frame = CGRect(x:0, y: tixingImage.originY+tixingImage.height+20, width:SCREEN_WHIDTH() , height:20 )
        tixingLabel.centerY = tixingImage.centerY + 50
        self.view.addSubview(tixingLabel)
    }
    
    func initDragCollectionView(){
        cellNum = 4
        self.dataSource = NSMutableArray()
        //initData()
        delegate.dataSource = self.dataSource
        delegate.cellNum = self.cellNum
        delegate.block = {[weak self](value:Any) in
            let model:UpcomingCollectionViewCellModel = value as! UpcomingCollectionViewCellModel
            //print(model.titleValue)
//            self?.actionGotoWeb(webViewUrl: model.url!, isHomePushType: .YesIsHomePushType, isShowTitleType: .YesShowTitleType)
        }
        self.view.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.width.height.equalToSuperview()
            make.center.equalToSuperview()
        }
        collectionView.delegate = self.delegate
        collectionView.dataSource = self.delegate
    }
//    func getServiceCollectionViewCellModel(httpModel:UpcomingSystemModel)->UpcomingCollectionViewCellModel{
//        let detailModel = UpcomingCollectionViewCellModel()
//        detailModel.className = "UpcomingCollectionViewCell"
//        detailModel.titleValue = httpModel.name
//        detailModel.imageName = httpModel.content.imageUrl
//        detailModel.biaojiNum = httpModel.count
//        detailModel.block = { [weak self](value:Any) in
////            self?.gotoListVC(model: httpModel)
//            self?.classAction(selecHttpModel: httpModel.content)
//        }
//       return detailModel
//    }
    func getServiceCollectionViewCellModelNew(httpModel:ApplicationHttpListModel)->UpcomingCollectionViewCellModel{
        let detailModel = UpcomingCollectionViewCellModel()
        detailModel.className = "UpcomingCollectionViewCell"
        detailModel.titleValue = httpModel.name
        detailModel.imageName = httpModel.imageUrl
        detailModel.biaojiNum = "0"
        detailModel.key = httpModel.todokey
        detailModel.type = httpModel.todotype
        detailModel.block = { [weak self](value:Any) in
//            self?.gotoListVC(model: httpModel)
//            self?.classAction(selecHttpModel: httpModel)
            self?.refreshTokenHttpAction(selecHttpModel: httpModel)
        }
        return detailModel
    }
//    func openWeb(httpModel:UpcomingSystemModel){
//        let url:String = AccountInfo.sharedInstance().getServiceVCUrl()+httpModel.id!
////        self.appViewsSstatistics(httpModel: httpModel)
//        //value1 备选页面
//        if httpModel.value1?.count != 0 {
//            self.actionGotoTitleWeb(webViewUrl: httpModel.value1!, title: httpModel.title!, isHomePushType: .YesIsHomePushType)
//        }else{
//            self.actionGotoTitleWeb(webViewUrl: url, title: httpModel.title!, isHomePushType: .YesIsHomePushType)
//        }
//    }
    /// 应用访问量
    func appViewsSstatistics(title:String,scope:String){
        let model = ClickRateModel()
        model.name = title
        model.belong = "门户"
        model.scope = scope
        model.type = "1"
        self.getClickRateHttpCmd(infoModel: model)
    }
    
}
class UpcomingViewControllerDelegate: NSObject ,UICollectionViewDelegate,UICollectionViewDataSource{
    var dataSource:NSMutableArray!
    var oneCellArray:NSMutableArray!
    var twoCellArray:NSMutableArray!
    var updateBlock:passParameterBlock!
    var btnViewWidth = CGFloat()
    var btnViewHeight = CGFloat()
    var cellNum:Double!
    var arrayIndex: Int!
    var editStatusType:EditStatusType = .StartEditing
    var block:passParameterBlock!
    
    //MARK: - 代理方法
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return self.dataSource.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "UpcomingCollectionViewCell", for: indexPath) as! UpcomingCollectionViewCell
        let info:BaseCollectionViewCellModel = dataSource[indexPath.row] as! BaseCollectionViewCellModel
        cell.configurateTheCell(info: info)
        return cell
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//        let info:UpcomingCollectionViewCellModel = dataSource[indexPath.row] as! UpcomingCollectionViewCellModel
//        if info.id != nil && info.id?.count != 0 {
//            info.block(info)
//        }
    }
}
