//
//  SideBarView.swift
//  wyy
//
//  Created by 施书顺 on 2021/3/6.
//

import UIKit
import SnapKit

class SideBarView: UIView, UITableViewDataSource, UITableViewDelegate {
    
    struct SideBarCellData {
        var imageName: String
        var title: String
    }
    
    let centerTableView = UITableView()
    var centerTableData = [SideBarCellData(imageName: "discover", title: "消息中心"),
                           SideBarCellData(imageName: "discover", title: "消息中心"),
                           SideBarCellData(imageName: "discover", title: "消息中心")]

    init(){
        super.init(frame: CGRect(x: 0, y: 0, width: 300, height: 1000))
        
        addSubview(centerTableView)
        centerTableView.dataSource = self
        centerTableView.delegate = self
        centerTableView.snp.makeConstraints { make in
            make.top.equalTo(20)
            make.centerX.equalToSuperview()
            make.width.equalTo(300)
            make.height.equalTo(800)
        }
        centerTableView.reloadData()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch tableView {
        case centerTableView:
            return centerTableData.count
        default:
            return 0
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellID = "sideBarCell"
        var cell: SideBarCell? = tableView.dequeueReusableCell(withIdentifier: cellID) as? SideBarCell
        if cell == nil {
            cell = SideBarCell(style: .subtitle, reuseIdentifier: cellID)
        }
        var data: SideBarCellData
        switch tableView {
        case centerTableView:
            data = centerTableData[indexPath.row]
        default:
            data = centerTableData[indexPath.row]
        }
        
        cell?.iconImageView.image = UIImage(named: data.imageName)
        cell?.titleLabel.text = data.title
        print(111)
        return cell!
    }
    
}
