//
//  TSEditLiveEidtCell.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/30.
//


class TSEditLiveSectionModel: CollectionViewSectionComponent{
    var style:ImageDataStyple = .homeLiveBanner
    var items:[TSEditLiveItemModel] = [TSEditLiveItemModel]()

    var sectionInset: UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    }
    
    var lineSpacing: CGFloat {
        return 0
    }
    
    var itemSpacing: CGFloat {
        return 0
    }
    var headerComponent: CollectionViewReuseViewComponent? {
        return nil
    }
    
    var cells: [CollectionViewCellComponent] {
        return items
    }

}
class TSEditLiveItemModel: CollectionViewCellComponent {
    var style:ImageDataStyple = .homeLiveBanner
    
    var imageUrl:String = ""
    var videoUrl:String = ""
    
    var cellClass: UICollectionViewCell.Type {
        return TSEditLiveEidtCell.self
    }
    
    func cellSize(with attrubites: [String : Any]?) -> CGSize {
        return CGSize(width: k_ScreenWidth, height: 414*kDesignScale)
    }
}


class TSEditLiveEidtCell : TSBaseCollectionCell , ComponentView{
    
    var component:CollectionViewComponent?
    
    override func creatUI() {
        let topEditView = creatTopEditVideoView()
        bgContentView.addSubview(topEditView)
        topEditView.snp.makeConstraints { make in
            make.top.leading.trailing.equalTo(0)
            make.height.equalTo(414*kDesignScale)
        }
    }
    
    
    func creatTopEditVideoView() -> UIView {
        
        let bgView = UIView()
        
        let videoUpImageView = UIImageView.createImageView(imageName: "video_up")
        bgView.addSubview(videoUpImageView)
        videoUpImageView.snp.makeConstraints { make in
            make.top.equalTo(80)
            make.centerX.equalToSuperview()
            make.width.height.equalTo(153)
        }
        
        let videoText = UILabel.createLabel(text: "Upload Video".localized,font: UIFont.systemFont(ofSize: 16, weight: .medium),textColor: .white,textAlignment: .center)
        bgView.addSubview(videoText)
        videoText.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.top.equalTo(videoUpImageView.snp.bottom).offset(12)
            make.height.equalTo(16)
        }
        
        let diyBtn: UIButton = TSViewTool.createNormalSubmitBtn(title: "DIY Live Wallpaper".localized, imageNamed: "edit_black") { [weak self]  in
            guard let self = self else { return }
  
            if let component = self.component {
                if let itemActionHandler = component.itemActionHandler {
                    itemActionHandler(self, IndexPath(row: 0, section: 0))
                }
            }
        }
        
        diyBtn.cornerRadius = 30
        bgView.addSubview(diyBtn)
        diyBtn.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.top.equalTo(videoText.snp.bottom).offset(53)
            make.height.equalTo(60)
        }
        
        return bgView
    }
    
    func renderView(with object: Any?, component: CollectionViewComponent, attributes: [String : Any]?) {
        self.component = component
    }
    

}
