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

class TSSetingCell: UITableViewCell {
    
    open lazy var bgContentView:UIView = {
        let view = UIView()
        view.backgroundColor = .white
        return view
    }()
    
    public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = .clear
        self.addSubview(bgContentView)
        bgContentView.snp.makeConstraints { make in
            make.top.leading.trailing.bottom.equalTo(0)
        }
        creatUI()
    }
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var leftImageView: UIImageView = {
        return UIImageView()
    }()
    
    lazy var leftLab: UILabel = {
        return UILabel.createLabel(font: .font(name:.PoppinsBoldItalic,size: 14),textColor: .mainText)
    }()
     
    lazy var rightLab: UILabel = {
        return UILabel.createLabel(font: .font(name:.PingFangSC,size: 14),textColor: .mainText )
    }()
    
    lazy var rightImageView: UIImageView = {
        return UIImageView.createRightArrow()
    }()
    
    
    lazy var dotView: UIView = {
        let view = UIView()
        view.backgroundColor = "#FF2B2B".uiColor
        view.cornerRadius = 2
        view.isHidden = true
        return view
    }()
    
    var itemModel:TSSetingModel?{
        didSet{
            guard let itemModel = itemModel else { return }
            leftImageView.image = itemModel.leftImage
            leftLab.text = itemModel.leftTitle
            rightLab.text = itemModel.rightString
//            dotView.isHidden = !itemModel.isWhether
            
            bgContentView.makeCorner(itemModel.rectCorner, radius: 20)
        }
    }
    
    func creatUI() {
        bgContentView.addSubview(leftImageView)
        bgContentView.addSubview(leftLab)
        bgContentView.addSubview(rightLab)
        bgContentView.addSubview(rightImageView)
        bgContentView.addSubview(dotView)
        
        leftImageView.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(24)
        }
        
        leftLab.snp.makeConstraints { make in
            make.leading.equalTo(leftImageView.snp.trailing).offset(16)
            make.centerY.equalToSuperview()
        }
        
        rightLab.snp.makeConstraints { make in
            make.trailing.equalTo(rightImageView.snp.leading).offset(-4)
            make.centerY.equalToSuperview()
        }
        
        rightImageView.snp.makeConstraints { make in
            make.trailing.equalTo(-16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(16)
        }
        
        dotView.snp.makeConstraints { make in
            make.trailing.equalTo(rightLab.snp.leading).offset(-4)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(4)
        }
        
    }

}
