//
//  SpeakEleProgressViewCtr.swift
//  SpeakEasyLearnEnglish
//
//  Created by mac on 2025/7/15.
//

import UIKit

class SpeakEleProgressViewCtr: SpeakEleBaseViewCtr {

    enum ProgressData:Int {
        case headerSign // 签到
        case studyTm    // 时长
        case review     // 数据
        case list       // 按钮列表
    }
    
    private var dataSource:[ProgressData] = [.headerSign ,.studyTm ,.review ,.list]
    
    @IBOutlet weak var SpeakTableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.init(with: "#F6F7F9")
    }
    
    override func setup() {
        self.SpeakTableView.delegate = self
        self.SpeakTableView.dataSource = self
        self.SpeakTableView.backgroundColor = .clear
        self.SpeakTableView.sectionHeaderTopPadding = 0
        self.SpeakTableView.register(UINib(nibName: SpeakProgressSignCell.id, bundle: nil), forCellReuseIdentifier: SpeakProgressSignCell.id)
        self.SpeakTableView.register(UINib(nibName: SpeakProgressStudyCell.id, bundle: nil), forCellReuseIdentifier: SpeakProgressStudyCell.id)
        self.SpeakTableView.register(UINib(nibName: SpeakProgressReviewCell.id, bundle: nil), forCellReuseIdentifier: SpeakProgressReviewCell.id)
        self.SpeakTableView.register(UINib(nibName: SpeakEleProgressListCell.id, bundle: nil), forCellReuseIdentifier: SpeakEleProgressListCell.id)
        self.SpeakTableView.showsVerticalScrollIndicator = false
        self.SpeakTableView.showsHorizontalScrollIndicator = false
    }
    
}

extension SpeakEleProgressViewCtr: UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let state = dataSource[indexPath.row]
        if state == .headerSign {
            let cell = tableView.dequeueReusableCell(withIdentifier: SpeakProgressSignCell.id, for: indexPath) as! SpeakProgressSignCell
            cell.selectionStyle = .none
            return cell
        }else if state == .studyTm {
            let cell = tableView.dequeueReusableCell(withIdentifier: SpeakProgressStudyCell.id, for: indexPath) as! SpeakProgressStudyCell
            cell.selectionStyle = .none
            return cell
        }else if state == .review{
            let cell = tableView.dequeueReusableCell(withIdentifier: SpeakProgressReviewCell.id, for: indexPath) as! SpeakProgressReviewCell
            cell.selectionStyle = .none
            return cell
        }else{
            let cell = tableView.dequeueReusableCell(withIdentifier: SpeakEleProgressListCell.id, for: indexPath) as! SpeakEleProgressListCell
            cell.selectionStyle = .none
            cell.callblack = { [weak self] idx in
                if let i = idx as? Int {
                    if i == 2 {
                        let history = SpeakProgressHistoryViewCtr()
                        self?.parent?.navigationController?.pushViewController(history, animated: true)
                    }
                }
            }
            return cell
        }
    }
    
}
