//
//  TSRandomWallpaperCell.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/22.
//


//MARK: TSRandomWallpaperCell
class TSRandomWallpaperCell: TSBaseCollectionCell , ComponentView {

    
    static let reuseIdentifier = "TSHomeCyclePagerViewCell"
    
    lazy var showImageView: UIImageView = {
        return UIImageView.createImageView(imageName: "", corner: 16)
    }()
    
    lazy var show1ImageView: UIImageView = {
        return UIImageView.createImageView(imageName: "", corner: 16)
    }()
    
    lazy var show2ImageView: UIImageView = {
        return UIImageView.createImageView(imageName: "", corner: 16)
    }()
    
    
    override func creatUI() {

        bgContentView.addSubview(show2ImageView)
        bgContentView.addSubview(show1ImageView)
        bgContentView.addSubview(showImageView)

        showImageView.snp.makeConstraints { make in
            make.leading.equalTo(0)
            make.trailing.equalTo(-32)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }

        show1ImageView.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.top.equalTo(13)
            make.bottom.equalTo(-11.66)
        }
        
        show2ImageView.snp.makeConstraints { make in
            make.leading.equalTo(35)
            make.trailing.equalTo(0)
            make.top.equalTo(26)
            make.bottom.equalTo(-23.66)
        }
    }
    
    func renderView(with object: Any?, component: CollectionViewComponent, attributes: [String : Any]?) {
        if let itemModel = object as? TSRandomWallpaperDataItemModel {
            
            if let model = itemModel.items.safeObj(At: 0), model.imageUrl.contains("http") {
                showImageView.setAsyncImage(urlString: model.imageUrl,placeholder: kWapppaperPlaceholderImage)
            }
            
            if let model = itemModel.items.safeObj(At: 1), model.imageUrl.contains("http") {
                show1ImageView.setAsyncImage(urlString: model.imageUrl,placeholder: kWapppaperPlaceholderImage)
            }
            
            if let model = itemModel.items.safeObj(At: 2), model.imageUrl.contains("http") {
                show2ImageView.setAsyncImage(urlString: model.imageUrl,placeholder: kWapppaperPlaceholderImage)
            }
        }
    }
}

