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

import UIKit

class MineCollectionViewCell: BaseCollectionViewCell {
    var block:passParameterBlock!
    var modelHttp = MineCollectionViewCellModel()
    var text :String!
    
    override func awakeFromNib() {
        super.awakeFromNib()
//        self.backgroundColor = UIColor.yellow
        self .addSubview(bagView)
        self .addSubview(titleImage)
        self .addSubview(titleLable)
        self .addSubview(bagBtn)
        self .addSubview(baojiBtn)
    }
    lazy var bagView: UIImageView = {
        let bagView = UIImageView.init()
//        bagView.backgroundColor = moreClassColor
//        bagView.backgroundColor = UIColor.red
        bagView.isHidden = true
        return bagView
    }()
    override func configurateTheCell(info:BaseCollectionViewCellModel){
        
        self.modelHttp = info as! MineCollectionViewCellModel
        self.block = self.modelHttp.block
        bagBtn.frame = CGRect(x:0, y: 0, width:self.width , height:self.height)
//        let titleImageW = self.width-73*WHIDTH_RATIO()
        let titleImageW = 26*WHIDTH_RATIO()
        titleImage.frame = CGRect(x:(self.width-titleImageW)/2, y: 10*WHIDTH_RATIO(), width:titleImageW , height:titleImageW )
        
        let titleLableH = getTextHeigh(textStr: judgmentStrNil(str: modelHttp.titleValue!), font: UIFont.systemFont(ofSize: 14*WHIDTH_RATIO()), width: self.width-10*WHIDTH_RATIO())
        titleLable.frame = CGRect(x:5*WHIDTH_RATIO(), y: titleImage.originY+titleImage.height+5*HEIGHT_RATIO(), width:self.width-10*WHIDTH_RATIO() , height:titleLableH )
        
        if modelHttp.imageName == "more_image" {
            titleImage.image = UIImage.init(named: "more_image")
        }else{
            titleImage.sd_setImage(with: URL.init(string: modelHttp.imageName!), placeholderImage: UIImage.init(named: "center_image"))
        }
        titleLable.text = modelHttp.titleValue
        let baojiBtnWidth = self.titleImage.width/2.2
        baojiBtn.frame = CGRect(x:self.titleImage.originX+self.titleImage.width-baojiBtnWidth, y: self.titleImage.originY/2, width:baojiBtnWidth , height:baojiBtnWidth)
        if self.modelHttp.biaojiNum == nil || self.modelHttp.biaojiNum?.count == 0 || self.modelHttp.biaojiNum == "0"{
            baojiBtn.isHidden = true
        }else{
            baojiBtn.isHidden = false
            baojiBtn.setTitle(self.modelHttp.biaojiNum, for: .normal)
        }
        if self.modelHttp.applicationType == .MyApplicationType && self.modelHttp.comments?.count == 0 {
            bagView.isHidden = false
            bagView.frame = CGRect(x:self.width-10*WHIDTH_RATIO()-baojiBtnWidth, y: 5*HEIGHT_RATIO(), width:baojiBtnWidth , height:baojiBtnWidth )
            if self.modelHttp.isInstallation == false{
                bagView.image = UIImage.init(named: "Yes_installation_image")
            }else{
                bagView.image = UIImage.init(named: "No_installation_image")
            }
        }else if self.modelHttp.applicationType == .MyApplicationType && self.modelHttp.comments?.count != 0{
            bagView.isHidden = true
        }else{
            bagView.isHidden = true
        }
    }
    
    lazy var titleImage: UIImageView = {
        let titleImage = UIImageView.init()
        titleImage.contentMode = .scaleAspectFit
        //titleImage.clipsToBounds = true
        return titleImage
    }()
    
    lazy var titleLable: UILabel = {
        let titleLable = UILabel.init()
        titleLable.textAlignment = .center
        titleLable.font = UIFont.systemFont(ofSize: 14*WHIDTH_RATIO())
        titleLable.numberOfLines = 0
        titleLable.backgroundColor = UIColor.clear
        titleLable.lineBreakMode = .byCharWrapping
        titleLable.textColor = blackTitleColor
        return titleLable
    }()
    
    lazy var bagBtn: UIButton = {
        let bagBtn = UIButton.init(type: .custom)
        bagBtn.alpha = 0.1
        bagBtn.backgroundColor = UIColor.clear
        bagBtn.addTarget(self, action: #selector(actions), for: .touchUpInside)
        return bagBtn
    }()
    lazy var baojiBtn: UIButton = {
        let baojiBtn = UIButton.init(type: .custom)
        baojiBtn.setTitleColor(UIColor.white, for: .normal)
        baojiBtn.titleLabel?.font = UIFont.systemFont(ofSize: 10)
        baojiBtn.setBackgroundImage(UIImage.init(named: "biaoji_image"), for: .normal)
        baojiBtn.isHidden = true
        return baojiBtn
    }()
    @objc func actions() {
        //if self.modelHttp.url != nil && self.modelHttp.url?.characters.count != 0 {
        self.block(self.modelHttp.comments as AnyObject)
        //}
    }
}
class MineCollectionViewCellModel: BaseCollectionViewCellModel {
    var titleValue:String?
    var imageName:String?
    var block:passParameterBlock!
    var isInstallation = true
    var biaojiNum:String?
    
    //var url:String?
    var comments:String?
    var openUrl:String?
    var httpDetailModel = AdvisoryHttpListModel()
    var applicationType:ApplicationType = .OftenApplicationType
}
