//
//  TSGenmojiGennerateCell.swift
//  AIEmoji
//
//  Created by 100Years on 2025/1/17.
//

class TSGenmojiGennerateCell : TSBaseCollectionCell{
    lazy var robotImageView: UIImageView = {
        let robotImageView = UIImageView.createImageView(imageName: "genmoji_robot")
        return robotImageView
    }()
    
    lazy var customTextView: TSCustomTextView = {
        let customTextView = TSCustomTextView(
            placeholder: "Enter your text here...",
            text: "",
            font: .font(size: 12),
            textColor: .white,
            backgroundColor: "#333333".color,
            textInsets: UIEdgeInsets(top: 21, left: 16, bottom: 21, right: 16)
        )
        customTextView.delegate = self
        customTextView.layer.cornerRadius = 12
        return customTextView
    }()
    
    
    lazy var submitBtn: UIButton = {
        let submitBtn = kCreateNormalSubmitBtn(title: "Generate".localized) { [weak self]  in
            guard let self = self else { return }
            actionHandler(any: customTextView.text)
        }
        submitBtn.cornerRadius = 24.0
        submitBtn.isEnabled = true
        return submitBtn
    }()
    
    
    override func creatUI() {
        
        contentView.addSubview(robotImageView)
        robotImageView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.leading.equalTo(0)
            make.width.height.equalTo(82)
        }
        
        contentView.addSubview(customTextView)
        customTextView.snp.makeConstraints { make in
            make.top.equalTo(57)
            make.leading.equalTo(17)
            make.trailing.equalTo(-15)
            make.height.equalTo(182.0*kDesignScale)
        }
        
        contentView.addSubview(submitBtn)
        submitBtn.snp.makeConstraints { make in
            make.top.equalTo(customTextView.snp.bottom).offset(16)
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.height.equalTo(48)
        }
    }
}

extension TSGenmojiGennerateCell: UITextViewDelegate{
    func textViewDidChange(_ textView: UITextView) {
        submitBtn.isEnabled = textView.text.count > 0
    }
}
