//
//  TSThemeContentCell.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/2.
//

class TSThemeContentCell: TSBaseCollectionCell {
    
    lazy var answerBgImageView: UIImageView = {
        let answerBgImageView = UIImageView.createImageView(imageName:"theme_answer_mask",contentMode: .scaleAspectFill)
        return answerBgImageView
    }()
    
    
    lazy var answerView: UIView = {
        let answerView = UIView()
        answerView.frame = CGRectMake(0, 0, 135, 36)
//        answerView.applyGaussianBlur(blurRadius: 1.0)
        let blurEffect = createBlurEffectView(style: .systemUltraThinMaterial)
        answerView.addSubview(blurEffect)
        blurEffect.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        let photoImageView = UIImageView.createImageView(imageName:"theme_answer_phone",contentMode: .scaleAspectFill)
        answerView.addSubview(photoImageView)
        photoImageView.snp.makeConstraints { make in
            make.leading.equalTo(2)
            make.width.equalTo(32)
            make.height.equalTo(32)
            make.centerY.equalToSuperview()
        }
        
        let textLabel = UILabel.createLabel(
            text: "Slide to answer".localized,
            font: .font(size: 10,weight: .medium),
            textColor: "#111111".uiColor
        )
        answerView.addSubview(textLabel)
        textLabel.snp.makeConstraints { make in
            make.leading.equalTo(45)
            make.centerY.equalToSuperview()
        }
        answerView.cornerRadius = 18.0
        return answerView
    }()
    
    
    
    lazy var showImageView: UIImageView = {
        let showImageView = UIImageView.createImageView(imageName:"",contentMode: .scaleAspectFill)
        showImageView.backgroundColor = .gray
        showImageView.layer.cornerRadius = 18
        return showImageView
    }()
    

    lazy var nameLabel:UILabel  = {
        let textLabel = UILabel.createLabel(
            text: "",
            font: .font(size: 26,weight: .bold),
            textColor: .white
        )
        textLabel.addShadow(shadowColor: UIColor.black.cgColor, shadowOffset: CGSize(width: 0, height: 2), shadowRadius: 5, shadowOpacity: 0.3)
        return textLabel
    }()
    
    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(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.top.equalTo(48)
            make.height.equalTo(36)
            make.centerX.equalToSuperview()
        }
        
        contentView.addSubview(answerView)
        answerView.snp.makeConstraints { make in
            make.bottom.equalTo(-30)
            make.width.equalTo(135)
            make.height.equalTo(36)
            make.centerX.equalToSuperview()
        }

    }
    
    
    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 themeModel = itemModel.dataModel as? TSThemeModel{
                showImageView.setAsyncImage(urlString: themeModel.poster,placeholder: kPlaceholderImage,contentMode: .scaleAspectFill)
                nameLabel.text = themeModel.name
            }
        }
    }
    
}
