//
//  QSLMineFuncTableViewCell.swift
//  QuickSearchLocation
//
//  Created by Destiny on 2024/4/16.
//

import UIKit

class QSLMineFuncTableViewCell: UITableViewCell {
    
    var cellDict:[String: String]? {
        didSet {
            updateUI()
        }
    }
    
    lazy var cellIcon: UIImageView = {
        
        let imageView = UIImageView()
        imageView.image = UIImage(named: "")
        return imageView
    }()
    
    lazy var cellLabel: UILabel = {
       
        let label = UILabel()
        label.font(15)
        label.textColor = QSLColor.Color_202020
        return label
    }()
    
    lazy var arrowIcon: UIImageView = {
       
        let imageView = UIImageView()
        imageView.image = UIImage(named: "mine_func_arrow")
        return imageView
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension QSLMineFuncTableViewCell {
    
    func updateUI() {
        
        if let dict = self.cellDict {
            
            let image = UIImage(named: dict["image"] ?? "")
            self.cellIcon.image = image
            
            self.cellLabel.text = dict["title"]
        }
    }
    
    func setUpUI() {
        
        addSubview(cellIcon)
        addSubview(cellLabel)
        addSubview(arrowIcon)
        
        cellIcon.snp.makeConstraints { make in
            make.left.equalTo(12.rpx)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
        }
        
        cellLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(cellIcon.snp.right).offset(8.rpx)
        }
        
        arrowIcon.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-12.rpx)
        }
    }
}
