//
//  TSPlogBannerCell.swift
//  KittensTravelNotes
//
//  Created by 100Years on 2025/7/5.
//

private var animationIndex:Int = 0
class TSPlogBannerCell: TSPlogBaseCell {
    override func upDateModel() {
        if let imageUrls = items as? [String] {
            imageView.startImageTransitionAnimation(index: animationIndex,datas: imageUrls) { [weak self] index,imageUrl in
                guard let self = self else { return }
                guard let imageUrl = imageUrl as? String else { return }
                animationIndex = index
                self.imageView.setAsyncImage(urlString: imageUrl,placeholder: .plogPlaceholder)
            }
        }
    }

    lazy var decorationImageView: UIImageView = {
        let bgImageView = UIImageView.createImageView(image: .plogBanneDecoration)
        return bgImageView
    }()
    
    lazy var imageView: UIImageView = {
        let imageView = UIImageView.createImageView(contentMode: .scaleAspectFill)
        return imageView
    }()
    
    lazy var titleLab: UILabel = {
        let titleLab = UILabel.createLabel(text:"You define where your cats travel".localized,font: .font(name: .PoppinsBoldItalic,size: 16,weight: .bold),textColor:.mainText,numberOfLines: 0)
        return titleLab
    }()
    
    lazy var submitBtn: UIButton = {
        let btn = UIButton.createButton(title: "Go".localized,backgroundColor: "#111111".uiColor,font: .font(name: .PoppinsBoldItalic,size: 16),titleColor: .white,corner: 18)
        btn.isUserInteractionEnabled = false
        btn.contentEdgeInsets = UIEdgeInsets(top: 0, left: 38, bottom: 0, right: 38)
        return btn
    }()

    override func creatUI() {
        
        contentView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickView)))
        
        kMainAsync {
            self.bgContentView.addGradientBg(colors: [UIColor.themeColor.withAlphaComponent(0.97).cgColor,UIColor.themeColor.withAlphaComponent(0.18).cgColor],startPoint: CGPoint(x: 0.5, y: 0),endPoint: CGPoint(x: 0.5, y: 1))
        }
        
        bgContentView.cornerRadius = 16
         
        contentView.addSubview(decorationImageView)
        decorationImageView.snp.makeConstraints { make in
            make.trailing.equalTo(0)
            make.width.equalTo(167)
            make.height.equalTo(150)
            make.bottom.equalTo(-2)
        }
        
        decorationImageView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.leading.equalTo(41)
            make.top.equalTo(27)
            make.width.equalTo(93)
            make.height.equalTo(90)
        }
        
        let leading = 12.0
        bgContentView.addSubview(titleLab)
        titleLab.snp.makeConstraints { make in
            make.trailing.equalTo(-167)
            make.leading.equalTo(leading)
            make.top.equalTo(16)
        }

        bgContentView.addSubview(submitBtn)
        submitBtn.snp.makeConstraints { make in
            make.bottom.equalTo(-16)
            make.leading.equalTo(leading)
            make.top.equalTo(titleLab.snp.bottom).offset(8)
            make.height.equalTo(36)
        }
    }
    
    @objc func clickView(){
        clickBlock?(TSAIDataItemModel(style: .ptp, viewModel: TSAIDataBaseItemVM(title: "")))
     }
}
