//
//  ChatResponseTokenCell.swift
//  Visual_Novel_iOS
//
//  Created by mh on 2025/10/27.
//

import UIKit

//  token
struct TokenRow: RowModel {
    let count: String
    var cellReuseID: String { "ChatResponseTokenCell" }
    func cellHeight(tableWidth: CGFloat) -> CGFloat { 50 }
}

class ChatResponseTokenCell: ChatSettingBaseCell, CellConfigurable {
    
    lazy var countLab: UILabel = {
        let lab = UILabel()
        lab.textColor = UIColor(hex: "#666666")
        lab.font = UIFont.boldSystemFont(ofSize: 14)
        lab.text = "0"
        lab.textAlignment = .center
        return lab
    }()
    
    lazy var subBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "role_setting_sub"), for: .normal)
        btn.addTarget(self, action: #selector(subBtnTap), for: .touchUpInside)
        return btn
    }()
    
    lazy var addBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "role_setting_add"), for: .normal)
        btn.addTarget(self, action: #selector(addBtnTap), for: .touchUpInside)
        return btn
    }()
    
    @objc func subBtnTap() {
        
    }
    
    @objc func addBtnTap() {
        
    }
    
    func configure(with row: RowModel) {
        guard let row = row as? TokenRow else { return }
        countLab.text = row.count
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        configureViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configureViews() {
        
        containerView.addSubview(subBtn)
        containerView.addSubview(countLab)
        containerView.addSubview(addBtn)
        
        countLab.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(subBtn.snp.right).offset(5)
            make.right.equalTo(addBtn.snp.left).offset(-5)
        }
        
        subBtn.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().inset(10)
            make.width.equalTo(25)
            make.height.equalTo(25)
        }
        
        addBtn.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().inset(10)
            make.width.equalTo(25)
            make.height.equalTo(25)
        }
    }
}
