//
//  HomeMoreCollectionViewCell.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/21.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

class HomeMoreCollectionViewCell: BaseCollectionViewCell {

    var block:passParameterBlock!
    var modelHttp = HomeMoreCollectionViewCellModel()
    var text :String!
    
    
   
    lazy var titleImage: UIImageView = {
        let titleImage = UIImageView.init()
        //titleImage.contentMode = .scaleAspectFill
        titleImage.backgroundColor = UIColor.clear
        return titleImage
    }()
    
    
    lazy var titleLable: UILabel = {
        let titleLable = UILabel.init()
        titleLable.textAlignment = .center
        titleLable.font = UIFont.systemFont(ofSize: 16*WHIDTH_RATIO())
        titleLable.numberOfLines = 0
        titleLable.backgroundColor = UIColor.clear
        titleLable.lineBreakMode = .byCharWrapping
        titleLable.textColor = blackTitleColor
        return titleLable
    }()
    
    lazy var operatingView: UIButton = {
        let operatingBtn = UIButton.init(type: .custom)
        operatingBtn.addTarget(self, action: #selector(operatingAction), for: .touchUpInside)
        operatingBtn.isHidden = true
        //        let operatingView = UIImageView.init()
        //        operatingView.isHidden = true
        return operatingBtn
    }()
    lazy var bagView: UIImageView = {
        let bagView = UIImageView.init()
        bagView.backgroundColor = moreClassColor
        return bagView
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        self.backgroundColor = UIColor.white
//        self .addSubview(bagView)
        self .addSubview(titleImage)
        self .addSubview(titleLable)
        self .addSubview(operatingView)
        let top:UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(action(tapGes: )))
        self.addGestureRecognizer(top)
    }
    override func configurateTheCell(info:BaseCollectionViewCellModel){
        
        self.modelHttp = info as! HomeMoreCollectionViewCellModel
        self.block = self.modelHttp.block
        
        bagView.frame = CGRect(x:2.5*WHIDTH_RATIO(), y: 2.5*HEIGHT_RATIO(), width:self.width-5*WHIDTH_RATIO() , height:self.width-5*WHIDTH_RATIO() )
        
        let titleImageW = self.width-73*WHIDTH_RATIO()
        titleImage.frame = CGRect(x:(self.width-titleImageW)/2, y: 10*WHIDTH_RATIO(), width:titleImageW , height:titleImageW )
        //titleLable.frame = CGRect(x:5*WHIDTH_RATIO(), y: titleImage.originY+titleImage.height+5*HEIGHT_RATIO(), width:self.width-10*WHIDTH_RATIO() , height:self.height-(titleImage.originY+titleImage.height+5*HEIGHT_RATIO()) )
        titleLable.frame = CGRect(x:5*WHIDTH_RATIO(), y: titleImage.originY+titleImage.height+5*HEIGHT_RATIO(), width:self.width-10*WHIDTH_RATIO() , height:getTextHeigh(textStr: modelHttp.titleValue!, font: UIFont.systemFont(ofSize: 15*WHIDTH_RATIO()), width: self.width-10*WHIDTH_RATIO()) )
        let baojiBtnWidth = titleImage.width/2.2
        operatingView.frame = CGRect(x:self.titleImage.originX+self.titleImage.width-baojiBtnWidth, y: self.titleImage.originY/2, width:baojiBtnWidth , height:baojiBtnWidth)
        if modelHttp.operationType == .AddType {
            //operatingView.image = UIImage.init(named: "moreDdd_image")
            operatingView.setBackgroundImage(UIImage.init(named: "moreDdd_image"), for: .normal)
        }else{
            //operatingView.image = UIImage.init(named: "moreDele_image")
            operatingView.setBackgroundImage(UIImage.init(named: "moreDele_image"), for: .normal)
        }
        titleImage.sd_setImage(with: URL.init(string: modelHttp.imageName!), placeholderImage: UIImage.init(named: "center_image"))
        //titleImage.image = UIImage.init(named: "agentServices_image")
        titleLable.text = modelHttp.titleValue
        
    }
    @objc func operatingAction(){
       
    }
    @objc func action(tapGes:UITapGestureRecognizer){
        self.block(self.modelHttp.comments!)
    }
}
class HomeMoreCollectionViewCellModel: BaseCollectionViewCellModel {
    var titleValue:String?
    var imageName:String?
    var block:passParameterBlock!
    var url:String?
    var operationType:OperationType = .DeleteType
    var comments:String?
    //var indexPath: IndexPath!
    
}
