//
//  TSGenmojiItemCell.swift
//  AIEmoji
//
//  Created by 100Years on 2025/1/17.
//

class TSGenmojiItemCell: TSBaseCollectionCell {
    
    lazy var exampleView: UIView = {
        let exampleView = UIView()
        exampleView.backgroundColor = "#232323".uiColor.withAlphaComponent(0.3)
        
        let textLabel = UILabel.createLabel(
            text: "Example".localized,
            font: .font(size: 12),
            textColor: .white
        )
        
        exampleView.addSubview(textLabel)
        textLabel.snp.makeConstraints { make in
            make.top.edges.equalTo(UIEdgeInsets(top: 4, left: 6, bottom: 4, right: 6))
        }
        exampleView.isHidden = true
        return exampleView
    }()
    
    lazy var showImageView: UIImageView = {
        let showImageView = UIImageView.createImageView(imageName:"",contentMode: .scaleAspectFill)
        showImageView.backgroundColor = .gray
        showImageView.layer.cornerRadius = 18
        return showImageView
    }()
    
    override func creatUI() {
        contentView.addSubview(showImageView)
        showImageView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.leading.equalTo(0)
            make.trailing.bottom.equalTo(0)
        }
        
        contentView.addSubview(exampleView)
        exampleView.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.leading.equalTo(8)
        }
    }
    
    
    override func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String : Any]?) {
        super.renderView(with: object, component: component, attributes: attributes)
        if let itemModel = object as? TSGenmojiCoLItemModel{
            if itemModel.dataModel.modelType == .example {
                exampleView.isHidden = false
                showImageView.image = UIImage(named: itemModel.dataModel.response.resultUrl)
            }else{
                exampleView.isHidden = true
                showImageView.setAsyncImage(urlString: itemModel.dataModel.response.resultUrl,contentMode: .scaleAspectFill)
            }
        }
    }
    
}
