//
//  TSDiscoverCell.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/17.
//

class TSDiscoverCell: TSBaseCollectionCell {
    static let cellID = "TSDiscoverCell"


    var itemModel:TSRingCategoryModel = TSRingCategoryModel(){
        didSet{
            imageView.image = UIImage(named: itemModel.cover)
            textLabel.text = itemModel.title
        }
    }
    
    lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        return imageView
    }()
    
    lazy var textLabel: UILabel = {
        let textLabel = UILabel.createLabel(font: .font(size: 14),textColor: .white,textAlignment: .center,numberOfLines: 0)
        textLabel.addShadow(shadowColor: UIColor.black.cgColor, shadowOffset: CGSize(width: 0, height: 2), shadowRadius: 2, shadowOpacity: 0.3)
        return textLabel
    }()
    
    override func creatUI() {
        bgContentView.cornerRadius = 16.0
        bgContentView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.top.bottom.leading.trailing.equalTo(0)
        }
        
        bgContentView.addSubview(textLabel)
        textLabel.snp.makeConstraints { make in
            make.leading.equalTo(6)
            make.trailing.equalTo(-6)
            make.top.equalTo(9)
        }
    }
    
    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 dataModel = itemModel.dataModel as? TSRingCategoryModel{
                imageView.setAsyncImage(urlString: dataModel.cover,placeholder:kPlaceholderImage,contentMode: .scaleAspectFill)
                textLabel.text = dataModel.title
            }
        }
    }
}
