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

import UIKit

class HeadlinesMoreDetailedTableViewCell: BaseTableViewCell {
    var xinfo = HeadlinesMoreDetailedTableViewCellModel()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.separatorInset=UIEdgeInsetsMake(0, 0, 0, 0)
//        self.separatorInset=UIEdgeInsetsMake(0, 30, 0, 0)
        self.contentView.addSubview(titleLabel)
        self.contentView.addSubview(timeLabel)
        self.contentView.addSubview(subImageView)
    }
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textAlignment = .left
        titleLabel.font = UIFont.test_systemFont(ofSize: 16*WHIDTH_RATIO())
        titleLabel.numberOfLines = 0
        //titleLabel.backgroundColor = UIColor.red
        titleLabel.textColor = blackTitleColor
        return titleLabel
    }()
    
    lazy var timeLabel: UILabel = {
        let timeLabel = UILabel.init()
        timeLabel.numberOfLines = 0
        timeLabel.textAlignment = .left
//        timeLabel.tintColor = grayColor
        timeLabel.textColor = grayColor
        timeLabel.font = UIFont.test_systemFont(ofSize: 14*WHIDTH_RATIO())
        return timeLabel
    }()
    lazy var subImageView: UIImageView = {
        let subImageView = UIImageView.init()
        //subImageView.contentMode = .scaleToFill
        subImageView.contentMode = .scaleAspectFill
        subImageView.clipsToBounds = true
        return subImageView
    }()
    override func configurateTheCell(_ info: BaseCellModel) {
        xinfo = info as! HeadlinesMoreDetailedTableViewCellModel
        var titleLabelW = CGFloat()
        
        if xinfo.imageUrl!.count == 0  {
            titleLabelW = SCREEN_WHIDTH()-20*WHIDTH_RATIO()
            subImageView.isHidden = true
        }else{
            subImageView.isHidden = false
            titleLabelW = SCREEN_WHIDTH()-140*WHIDTH_RATIO()
        }
        /// 图片
        subImageView.frame = CGRect(x:15*WHIDTH_RATIO(), y: 7*HEIGHT_RATIO(), width:100*WHIDTH_RATIO() , height:self.height-14*HEIGHT_RATIO())
        subImageView.sd_setImage(with: URL(string: xinfo.imageUrl!), placeholderImage: UIImage.init(named: "center_image"), completed: { (image, error, SDImageCacheTypeNone, url) in
            if error != nil{
                print(error!)
            }
        })
        
//        let titleLabelH = getTextHeigh(textStr: xinfo.titleStr!, font: UIFont.systemFont(ofSize: 16*WHIDTH_RATIO()), width: titleLabelW)
//        titleLabel.frame = CGRect(x:10*WHIDTH_RATIO(), y: (self.height-titleLabelH)/2-8*HEIGHT_RATIO(), width:titleLabelW , height:titleLabelH)
//
//        let timeLabelH = 14
//        let timeLabelW = titleLabelW
//        timeLabel.frame = CGRect(x:10*WHIDTH_RATIO(), y: titleLabel.originY+titleLabelH+8*HEIGHT_RATIO(), width:timeLabelW , height:CGFloat(timeLabelH))
//
//        titleLabel.text = xinfo.titleStr
//        timeLabel.text = xinfo.timeStr
        
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        if selected {
            self.xinfo.block()
        }
    }
    
}
class HeadlinesMoreDetailedTableViewCellModel: BaseCellModel {
    var titleStr:String?
    var imageUrl:String?
    var timeStr:String?
    var block:selectBlock!
    
}
