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

class TSAIDataHeaderView: UICollectionReusableView {
    
    var clickBlock:((TSAIDataSectionModel)->Void)?
    var sectionModel:TSAIDataSectionModel = TSAIDataSectionModel(){
        didSet{
            titleLab.text = sectionModel.title.localized
            moreView.isHidden = sectionModel.style != .styleMore
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        creatUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var decorationImageView:UIImageView = {
        let imageView = UIImageView.createImageView(image:.plogDecoration)
        return imageView
    }()
    
    lazy var titleLab: UILabel = {
        let titleLab = UILabel.createLabel(font: .font(name: .PoppinsBoldItalic,size: 16,weight: .medium),textColor: .mainText)
        return titleLab
    }()
    
    
    lazy var moreArrowImageView:UIImageView = {
        let imageView = UIImageView.createImageView(image:.moreArrow)
        return imageView
    }()
    
    
    lazy var rightLabel: UILabel = {
        let label = UILabel.createLabel(text: "More".localized,font: .font(size: 12),textColor: .mainText)
        return label
    }()
    
    lazy var moreView: UIView = {
        let moreView = UIView()
        moreView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickMoreView)))
        moreView.addSubview(rightLabel)
        rightLabel.snp.makeConstraints { make in
            make.leading.top.bottom.equalTo(0)
        }
     
        moreView.addSubview(moreArrowImageView)
        moreArrowImageView.snp.makeConstraints { make in
            make.trailing.top.bottom.equalTo(0)
            make.leading.equalTo(rightLabel.snp.trailing)
            make.width.height.equalTo(24)
        }
        
        return moreView
    }()
    
    
    
    func creatUI() {
        
        addSubview(decorationImageView)
        decorationImageView.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.top.equalTo(23)
            make.width.equalTo(64)
            make.height.equalTo(20)
        }

        addSubview(titleLab)
        titleLab.snp.makeConstraints { make in
            make.leading.equalTo(43)
            make.centerY.equalTo(decorationImageView)
        }
    
        
        addSubview(moreView)
        moreView.snp.makeConstraints { make in
            make.trailing.equalTo(-16)
            make.centerY.equalTo(decorationImageView)
        }
    }
    
    @objc private func clickMoreView() {
        clickBlock?(sectionModel)
    }
}
