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

import UIKit

class DetailsTableViewCell: BaseTableViewCell {

//    lazy var titleView: TitleView = {
//        let titleView = TitleView.init(frame: CGRect(x:12.33, y: 27, width:SCREEN_WHIDTH()-12.33 , height:65 ))
//        return titleView
//    }()
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textAlignment = .left
        titleLabel.numberOfLines = 0
        titleLabel.font = UIFont.systemFont(ofSize: 21.33)
        titleLabel.font = UIFont.test_boldSystemFont(21.33)
        titleLabel.font = UIFont.test_font(withName: 21.33)
        titleLabel.textColor = UIColorFromRGB(rgbValue: 0x1E202C)
        self.addSubview(titleLabel)
        return titleLabel
    }()
    lazy var webLabel: UILabel = {
        let webLabel = UILabel.init()
        webLabel.textAlignment = .left
        webLabel.numberOfLines = 0
        webLabel.font = UIFont.test_systemFont(ofSize: 16)
        webLabel.textColor = UIColorFromRGB(rgbValue: 0x3D444F)
        self.addSubview(webLabel)
        return webLabel
    }()
    lazy var subImageView: UIImageView = {
        let subImageView = UIImageView.init()
        //subImageView.contentMode = .scaleToFill
        subImageView.contentMode = .scaleAspectFill
        //        subImageView.backgroundColor = UIColor.yellow
        subImageView.image = UIImage.init(named: "bigQ_image")
        self.addSubview(subImageView)
        return subImageView
    }()
    var xinfo = DetailsTableViewCellModel()
    
    override func awakeFromNib() {
        super.awakeFromNib()
//        self.addSubview(titleView)
        self.separatorInset=UIEdgeInsetsMake(0, 15, 0, 15)
        // Initialization code
    }
    override func configurateTheCell(_ info: BaseCellModel) {
        xinfo = info as! DetailsTableViewCellModel
//        titleView.text = xinfo.titleStr
        self.subImageView.frame = CGRect(x:12.33, y: 27, width:46.67 , height:64.67 )
        titleLabel.frame = CGRect(x:31.67, y: subImageView.originY+30, width:self.width-40 , height:getTextHeigh(textStr: xinfo.titleStr!, font: UIFont.test_systemFont(ofSize: 21.33), width: self.width-20) )
        titleLabel.text = xinfo.titleStr
        webLabel.frame = CGRect(x:5, y: titleLabel.originY+titleLabel.height+10, width:SCREEN_WHIDTH()-10 , height:self.height-(titleLabel.originY+titleLabel.height+10) )
        do{
            let attrStr = try NSAttributedString(data: self.xinfo.content!.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
            webLabel.attributedText = attrStr
        }catch let error as NSError {
            print(error.localizedDescription)
        }

    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    func changeFontColor(totalString: String, subString: String, font: UIFont, textColor: UIColor)-> NSMutableAttributedString {
        let attStr = NSMutableAttributedString.init(string: totalString)
        attStr.addAttributes([NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: font], range: NSRange.init(location: totalString.count-subString.count, length: subString.count))
        return attStr
    }

}
class DetailsTableViewCellModel: BaseCellModel {
    var titleStr:String?
    var content:String?
    var block:selectBlock!
    var h = CGFloat()
    
}
