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

class TSGenmojiColSectionView: TSBaseCollectionnReusableView {
    
    static let reuseIdentifier = "TSHomeCollectionReusableView"
    lazy var leftLab: UILabel = {
        return UILabel.createLabel(font: .font(size: 16,weight: .medium),textColor: .fromHex("FFFFFF"))
    }()
    
    
    lazy var delBtn: UIButton = {
        let delBtn = UIButton.createButton(image: UIImage(named: "delete")){ [weak self]  in
            guard let self = self else { return }
            actionHandler(any: "delete")
        }
        return delBtn
    }()
    
    override func creatUI() {
        bgContentView.addSubview(leftLab)
        bgContentView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)))
        leftLab.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.centerY.equalToSuperview()
        }
        
        bgContentView.addSubview(delBtn)
        delBtn.snp.makeConstraints { make in
            make.trailing.equalTo(-6)
            make.width.height.equalTo(40)
            make.centerY.equalToSuperview()
        }
    }
    
    override func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String : Any]?) {
        super.renderView(with: object, component: component, attributes: attributes)
        if let componentReuseViewModel = object as? TSGenmojiColComponentReuseViewModel {
            leftLab.text = componentReuseViewModel.sectionModel.name
        }
    }
    
    @objc private func dismissKeyboard() {
        if let topVC = WindowHelper.topViewController() {
            topVC.view.endEditing(true) // 收起键盘
        }
    }

}

