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

import UIKit

//  font
struct FontRow: RowModel {
    let count: String
    let icon: String
    let title: String
    var cellReuseID: String { "ChatFontCell" }
    func cellHeight(tableWidth: CGFloat) -> CGFloat { 50 }
}
 
class ChatFontCell: ChatSettingBaseCell, CellConfigurable {
    
    lazy var iconImgView: UIImageView = {
        let imgView = UIImageView(image: UIImage(named: "role_exchange_mode"))
        return imgView
    }()
    
    lazy var titleLab: UILabel = {
        let lab = UILabel()
        lab.text = "XL-0826-32K"
        lab.font = UIFont.boldSystemFont(ofSize: 14)
        lab.textColor = UIColor(hex: "#666666")
        return lab
    }()
    
    lazy var fontSub: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "role_setting_font_sub"), for: .normal)
        btn.addTarget(self, action: #selector(fontSubTap), for: .touchUpInside)
        return btn
    }()
    
    lazy var fontAdd: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "role_setting_font_add"), for: .normal)
        btn.addTarget(self, action: #selector(fontAddTap), for: .touchUpInside)
        return btn
    }()
    
    lazy var fontLab: UILabel = {
        let lab = UILabel()
        lab.text = "20"
        lab.font = UIFont.systemFont(ofSize: 14)
        lab.textColor = UIColor(hex: "#999999")
        lab.textAlignment = .center
        return lab
    }()
    
    func configure(with row: RowModel) {
        guard let row = row as? FontRow else { return }
        titleLab.text = row.title
        iconImgView.image = UIImage(named: row.icon)
    }
    
    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(iconImgView)
        containerView.addSubview(titleLab)
        containerView.addSubview(fontSub)
        containerView.addSubview(fontAdd)
        containerView.addSubview(fontLab)
        
        iconImgView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(12)
            make.width.height.equalTo(21)
        }
        
        titleLab.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(iconImgView.snp.right).offset(9)
            make.right.equalTo(fontSub.snp.left).offset(-5)
        }
        
        fontAdd.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().inset(20)
            make.width.height.equalTo(40)
        }
        
        fontLab.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(fontAdd.snp.left).offset(-10)
        }
        
        fontSub.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(fontLab.snp.left).offset(-10)
            make.width.height.equalTo(40)
        }
    }
    
    @objc func fontSubTap() {
        print("sub sub sub")
    }
    
    @objc func fontAddTap() {
        print("add add add")
    }
}
