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

import UIKit

class DialogueLeftContentTVC: BaseTableViewCell {

    var xinfo = DialogueLeftContentTVCModel()
    
    lazy var headImageView: UIImageView = {
        let headImageView = UIImageView.init()
        headImageView.contentMode = .scaleAspectFill
        headImageView.image = UIImage.init(named: "home_image")
        return headImageView
    }()
    lazy var bagImageView: UIImageView = {
        let bagImageView = UIImageView.init()
        return bagImageView
    }()
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textAlignment = .left
        titleLabel.numberOfLines = 0
        titleLabel.textColor = UIColorFromRGB(rgbValue: 0x3D444F)
        titleLabel.font = UIFont.test_systemFont(ofSize: 13.33)
        return titleLabel
    }()
    lazy var webLabel: UILabel = {
        let webLabel = UILabel.init()
        webLabel.textAlignment = .left
        webLabel.numberOfLines = 0
        webLabel.textColor = UIColorFromRGB(rgbValue: 0x3D444F)
        webLabel.font = UIFont.test_systemFont(ofSize: 13.33)
//        webLabel.backgroundColor = UIColor.red
        return webLabel
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        self.separatorInset=UIEdgeInsetsMake(0, SCREEN_WHIDTH(), 0, 0)
        let insets = UIEdgeInsets.init(top: 12, left: 12, bottom: 10, right: 10)
        var aaimage = UIImage.init(named: "leftBag_image")
        aaimage = aaimage?.resizableImage(withCapInsets: insets, resizingMode: UIImageResizingMode.stretch)
        bagImageView.image = aaimage
        self.backgroundColor = UIColorFromRGB(rgbValue: 0xE9F2F8)
        self.addSubview(headImageView)
        self.addSubview(bagImageView)
        self.addSubview(titleLabel)
        self.addSubview(webLabel)
        // Initialization code
    }
    override func configurateTheCell(_ info: BaseCellModel) {
        xinfo = info as! DialogueLeftContentTVCModel
        headImageView.frame = CGRect(x:13.67, y: 20.67, width:57.33 , height:57.33 )
        let webLabelW = SCREEN_WHIDTH()-(headImageView.originX+headImageView.width+22.67+67)
        titleLabel.frame = CGRect(x:headImageView.originX+headImageView.width+23, y: headImageView.originY+24, width:webLabelW , height:xinfo.titleH )
        titleLabel.text = xinfo.titleStr
//        self.xinfo.content = self.xinfo.content?.replacingOccurrences(of: "13", with: "12")
//        self.xinfo.content = self.xinfo.content?.replacingOccurrences(of: "10", with: "8")

        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)
        }
        webLabel.frame = CGRect(x:titleLabel.originX, y: titleLabel.originY+titleLabel.height, width:webLabelW , height:xinfo.leftCellH )
        bagImageView.frame = CGRect(x:titleLabel.originX-13, y: titleLabel.originY-13, width: webLabelW+26, height:self.xinfo.leftCellH+titleLabel.height+13*2 )
//        print(webLabelW,selectionItemView.width)
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }

}
class DialogueLeftContentTVCModel: BaseCellModel {
    var titleStr:String?
    var content:String?
    var block:selectBlock!
    /// cell的累积高度
    var leftCellH:CGFloat!
    var titleH:CGFloat!
    var selectionArray = NSMutableArray()
}
