//
//  UpcomingListTableViewCell.swift
//  MobilePortal
//
//  Created by caiyang on 2020/4/22.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

class UpcomingListTableViewCell: BaseTableViewCell {
    var xinfo = UpcomingListTableViewCellModel()
    ///展开收回响应方法
    var retractUnfoldBlack:passParameterBlock!
    
    
    lazy var bagView: UIView = {
        let bagView = UIView.init()
        bagView.backgroundColor = UIColor.white
        //设置遮罩
        bagView.layer.masksToBounds = true
        //设置圆角半径(宽度的一半)，显示成圆形。
        bagView.layer.cornerRadius = 5
        return bagView
    }()
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textAlignment = .left
//        titleLabel.font = UIFont.boldSystemFont(ofSize: 13.33)
        titleLabel.font = UIFont.test_boldSystemFont(13.33)
        titleLabel.font = UIFont.test_font(withName: 13.33)
        titleLabel.numberOfLines = 0
        titleLabel.textColor = UIColorFromRGB(rgbValue: 0x23262A)
        return titleLabel
    }()
    lazy var upcomingTypeLabel: UILabel = {
        let upcomingTypeLabel = UILabel.init()
        upcomingTypeLabel.textAlignment = .left
        upcomingTypeLabel.font = UIFont.test_systemFont(ofSize: 11.67)
        upcomingTypeLabel.numberOfLines = 0
        upcomingTypeLabel.textColor = UIColorFromRGB(rgbValue: 0xE96625)
        return upcomingTypeLabel
    }()
    lazy var biaojiView: UIView = {
        let biaojiView = UIView.init()
        biaojiView.backgroundColor = UIColorFromRGB(rgbValue: 0xE96625)
        //设置遮罩
        biaojiView.layer.masksToBounds = true
        //设置圆角半径(宽度的一半)，显示成圆形。
        biaojiView.layer.cornerRadius = 5
        return biaojiView
    }()
    lazy var subLabel: UILabel = {
        let subLabel = UILabel.init()
        subLabel.textAlignment = .left
        subLabel.font = UIFont.test_systemFont(ofSize: 11.67)
        subLabel.numberOfLines = 0
        subLabel.textColor = UIColorFromRGB(rgbValue: 0x8792A4)
        return subLabel
    }()
    lazy var dateLabel: UILabel = {
        let dateLabel = UILabel.init()
        dateLabel.textAlignment = .right
        dateLabel.font = UIFont.test_systemFont(ofSize: 10.67)
        dateLabel.numberOfLines = 0
        dateLabel.textColor = UIColorFromRGB(rgbValue: 0x8792A4)
        return dateLabel
    }()
    lazy var minuteLabel: UILabel = {
        let minuteLabel = UILabel.init()
        minuteLabel.textAlignment = .right
        minuteLabel.font = UIFont.test_systemFont(ofSize: 10.67)
        minuteLabel.numberOfLines = 0
        minuteLabel.textColor = UIColorFromRGB(rgbValue: 0x8792A4)
        return minuteLabel
    }()
    private lazy var retractBtn: UIButton = {
        let retractBtn = UIButton.init()
        retractBtn.frame = CGRect(x:SCREEN_WHIDTH()-100, y: 0, width:40 , height:self.height )
        //        retractBtn.backgroundColor = statusBarColor
        retractBtn.setTitleColor(UIColor.white, for: .normal)
        retractBtn.addTarget(self, action: #selector(retractUnfoldBlackActioin), for: .touchUpInside)
        return retractBtn
    }()
    var retractUnfoldType:RetractUnfoldType = .Retractype {
        didSet {
            if retractUnfoldType == .Retractype {
                retractBtn.setBackgroundImage(UIImage.init(named: "unfold_image"), for: .normal)
            } else {
                retractBtn.setBackgroundImage(UIImage.init(named: "takeBack_image"), for: .normal)
            }
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        self.separatorInset = UIEdgeInsetsMake(0, SCREEN_WHIDTH(), 0, 0)
        self.backgroundColor = UIColorFromRGB(rgbValue: 0xF4F9FD)
        self.addSubview(bagView)
        self.addSubview(titleLabel)
        self.addSubview(subLabel)
        self.addSubview(dateLabel)
        self.addSubview(minuteLabel)
        self.addSubview(titleLabel)
//        self.addSubview(retractBtn)
//        self.addSubview(upcomingTypeLabel)
//        self.addSubview(biaojiView)
        // Initialization code
    }
    override func configurateTheCell(_ info: BaseCellModel) {
        xinfo = (info as! UpcomingListTableViewCellModel)
        self.retractUnfoldType = xinfo.retractUnfoldType
        self.retractUnfoldBlack = xinfo.retractUnfoldBlack
        bagView.frame = CGRect(x:13.33, y: 0, width:SCREEN_WHIDTH()-26.66 , height:self.height-10 )
        titleLabel.frame = CGRect(x:bagView.originX+15.33, y: 13, width: getTexWidth(textStr: xinfo.title!, font: UIFont.test_systemFont(ofSize: 14), height: 13), height:13 )
        titleLabel.text = xinfo.title
        subLabel.frame = CGRect(x:titleLabel.originX, y: titleLabel.originY+titleLabel.height+10, width: bagView.width-100, height:13 )
        subLabel.text = xinfo.subTitle
        
        let upcomingTypeLabelW:CGFloat = getTexWidth(textStr: xinfo.upcomingType.rawValue, font: UIFont.test_systemFont(ofSize: 12), height: 11)
        upcomingTypeLabel.frame = CGRect(x:SCREEN_WHIDTH()-upcomingTypeLabelW-26.66, y: titleLabel.originY-3, width: upcomingTypeLabelW, height:12 )
        upcomingTypeLabel.text = xinfo.upcomingType.rawValue
        biaojiView.frame = CGRect(x:upcomingTypeLabel.originX-15, y: titleLabel.originY-2, width: 10, height:10 )
//        let dateLabelW:CGFloat = getTexWidth(textStr: xinfo.dateTime!, font: UIFont.test_systemFont(ofSize: 11), height: 11)
//        dateLabel.frame = CGRect(x:SCREEN_WHIDTH()-dateLabelW-26.66, y: upcomingTypeLabel.originY+upcomingTypeLabel.height+3, width: dateLabelW, height:11 )
//        dateLabel.text = xinfo.dateTime
        let minuteLabelW:CGFloat = getTexWidth(textStr: xinfo.minuteTime!, font: UIFont.test_systemFont(ofSize: 11), height: 11)
        minuteLabel.frame = CGRect(x:SCREEN_WHIDTH()-minuteLabelW-26.66, y: dateLabel.originY+dateLabel.height+3, width: minuteLabelW, height:11 )
        minuteLabel.text = xinfo.minuteTime
        minuteLabel.originY = titleLabel.originY
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        if selected {
            self.xinfo.block()
        }
        // Configure the view for the selected state
    }
    @objc func retractUnfoldBlackActioin() {
        self.retractUnfoldBlack(self.retractUnfoldType)
    }
}
class UpcomingListTableViewCellModel: BaseCellModel {
    var title:String?
    var subTitle:String?
//    var upcomingType:String?
    var dateTime:String?
    var minuteTime:String?
    var block:selectBlock!
    var upcomingType:BusinessType = .UpcomingType
    var accessoryType:UITableViewCellAccessoryType = .none
    /// 是否展开收回
    var retractUnfoldType:RetractUnfoldType = .Retractype
    ///展开收回响应方法
    var retractUnfoldBlack:passParameterBlock!
    
}
