//
//  TSAIPhotoImageCell.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/5.
//

class TSAIPhotoImageCell: TSBaseCollectionCell {
    
    lazy var showImageView: UIImageView = {
        let showImageView = UIImageView.createImageView(imageName:"",contentMode: .scaleAspectFill)
        showImageView.backgroundColor = .gray
        return showImageView
    }()
    
    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
        exampleView.cornerRadius = 10.0
        return exampleView
    }()
    
    override func creatUI() {
        contentView.addSubview(showImageView)
        showImageView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.leading.equalTo(0)
            make.trailing.bottom.equalTo(0)
        }
        
        if self.bounds.size.width == self.bounds.size.height {
            showImageView.layer.cornerRadius = self.bounds.size.width/2
        }else{
            showImageView.layer.cornerRadius = 16
        }
        
        contentView.addSubview(exampleView)
        exampleView.snp.makeConstraints { make in
            make.bottom.equalTo(-8)
            make.centerX.equalToSuperview()
            make.height.equalTo(20)
        }
        
    }
    
    override func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String : Any]?) {
        super.renderView(with: object, component: component, attributes: attributes)
        if let itemModel = object as? TSColVVMItemModel{
            if let generalPicModel = itemModel.dataModel as? TSActionInfoModel{
                showImageView.image = nil
                showImageView.setAsyncImage(urlString: generalPicModel.response.resultUrl,placeholder: kPlaceholderImage,contentMode: .scaleAspectFill)
                exampleView.isHidden = generalPicModel.modelType == .example ? false : true
            }
        }
    }
    
}

