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

import UIKit

class HeadlinesMoreTableViewCell: BaseTableViewCell {
    @IBOutlet weak var titleImage: UIImageView!
    
    @IBOutlet weak var moreImage: UIImageView!
    
    var xinfo = HeadlinesMoreTableViewCellModel()
    
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textAlignment = .left
//        titleLabel.font = UIFont.systemFont(ofSize: 15)
//        titleLabel.font = UIFont.boldSystemFont(ofSize: 15)
//        titleLabel.font = UIFont.init(name: "Helvetica-Bold", size: 15)
        titleLabel.font = UIFont.test_boldSystemFont(15)
        titleLabel.font = UIFont.test_font(withName: 15)
        titleLabel.numberOfLines = 0
        titleLabel.text = "上药头条"
        //titleLabel.backgroundColor = UIColor.red
        titleLabel.textColor = UIColorFromRGB(rgbValue: 0x3D444F)
        return titleLabel
    }()
    lazy var moreBtn: UIButton = {
        let moreBtn = UIButton.init()
        moreBtn.setTitle("更多", for: .normal)
        moreBtn.setTitleColor(UIColorFromRGB(rgbValue: 0x8F9AAB), for: .normal)
//        moreBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        moreBtn.titleLabel?.font = UIFont.test_systemFont(ofSize: 12)
//        moreBtn.backgroundColor = UIColor.yellow
        moreBtn.contentHorizontalAlignment = .right
        moreBtn.titleLabel?.textColor = UIColorFromRGB(rgbValue: 0x8F9AAB)
        return moreBtn
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.backgroundColor = UIColor.white
        self.separatorInset=UIEdgeInsetsMake(0, SCREEN_WHIDTH(), 0, 0)
        self.contentView.addSubview(titleLabel)
        self.contentView.addSubview(moreBtn)
    }
    override func configurateTheCell(_ info: BaseCellModel) {
        xinfo = info as! HeadlinesMoreTableViewCellModel
        titleLabel.frame = CGRect(x:15, y: 0, width:self.width/2 , height:self.height )
        moreBtn.frame = CGRect(x:self.width/2, y: 0, width:self.width/2-15 , height:self.height )
        moreBtn.addTarget(self, action: #selector(actionBtn), for: .touchUpInside)
        
        
//        titleImage.sd_setImage(with: URL(string: judgmentStrNil(str: xinfo.titleImageUrl)), placeholderImage: UIImage.init(named: "center_image"), completed: { (image, error, SDImageCacheTypeNone, url) in
//            if (error != nil) {print(error!)}
//        })
//        moreImage.sd_setImage(with: URL(string: judgmentStrNil(str: xinfo.moreImageUrl)), placeholderImage: UIImage.init(named: "center_image"), completed: { (image, error, SDImageCacheTypeNone, url) in
//            if (error != nil) {print(error ?? Error.self)}
//        })
    }
    @objc func actionBtn() {
        xinfo.block()
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        if selected {
            if xinfo.block != nil && xinfo.pageUrl != nil {
                self.actionBtn()
            }
        }
    }

}
class HeadlinesMoreTableViewCellModel: BaseCellModel {
    
    var moreImageUrl:String?
    var titleImageUrl:String?
    var pageUrl:String?
    var block:selectBlock!
}
