//
//  TSHomeCell.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/21.
//

class TSHomeCollectionCell : TSBaseCollectionCell ,ComponentView{
    
    static let reuseIdentifier = "TSHomeCollectionCell"
    
    lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = kWapppaperPlaceholderImage
        return imageView
    }()
    
    lazy var liveIconView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = KIconLiveImage
        return imageView
    }()

    override func creatUI() {
        bgContentView.cornerRadius = 16
        
        bgContentView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        bgContentView.addSubview(liveIconView)
        liveIconView.snp.makeConstraints { make in
            make.left.equalTo(8)
            make.top.equalTo(8)
            make.width.height.equalTo(24)
        }
    }

    func renderView(with object: Any?, component: CollectionViewComponent, attributes: [String : Any]?) {
        if let itemModel = object as? TSImageDataItemModel{
            imageView.setAsyncImage(urlString: itemModel.imageUrl,placeholder: kWapppaperPlaceholderImage,showLoading: true)
        }
    }
}



//MARK: TSHomeCollectionReusableView
class TSHomeCollectionReusableView: TSBaseCollectionnReusableView,ComponentView{
    
    static let reuseIdentifier = "TSHomeCollectionReusableView"
    
    lazy var leftLab: UILabel = {
        return UILabel.createLabel(font: .font(size: 16,weight: .medium),textColor: .fromHex("FFFFFF", alpha: 0.8))
    }()
    override func creatUI() {
        bgContentView.addSubview(leftLab)
        leftLab.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.centerY.equalToSuperview()
        }
    }
    
    func renderView(with object: Any?, component: CollectionViewComponent, attributes: [String : Any]?) {
        if let componentReuseViewModel = object as? TSComponentReuseViewModel {
            leftLab.text = componentReuseViewModel.sectionModel.name
        }
    }
    
    

}
