//
//  YHMainViewController.swift
//  galaxy
//
//  Created by EDY on 2023/12/20.
//

import UIKit
import SnapKit

struct PersonalModuleItem {
    var icon: String
    var title: String
}

class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget {
    
    lazy var tableView: UITableView = {
        let tableView = UITableView(frame: CGRect.zero, style:.plain)
        tableView.backgroundColor = YHColorWithHex(0xE9E9E9)
        tableView.separatorStyle = .none
        tableView.register(YHPersonalCenterCell.self, forCellReuseIdentifier: YHPersonalCenterCell.cellReuseIdentifier)
        tableView.delegate = self
        tableView.dataSource = self
        return tableView
    }()
    
    lazy var smsInputView: YHSMSCodeInputView = {
         let codeView = YHSMSCodeInputView(frame: CGRectZero)
         return codeView
    }()
    
    lazy var items: [PersonalModuleItem] = {
        return [PersonalModuleItem(icon: "", title: "我的管家"),
                PersonalModuleItem(icon: "", title: "我的订单"),
                PersonalModuleItem(icon: "", title: "我的合同"),
                PersonalModuleItem(icon: "", title: "我的进度"),
                PersonalModuleItem(icon: "", title: "我的积分"),
                PersonalModuleItem(icon: "", title: "我的设置"),
                PersonalModuleItem(icon: "", title: "关于我们"),]
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        initView()
    }
    
    
    func initView() {
        navigationItem.title = "我的"
        view.backgroundColor = YHColorWithHex(0xE9E9E9)
        
        
        view.addSubview(tableView);
        tableView.snp.makeConstraints { make in
            make.left.right.top.bottom.equalTo(view)
        }
        
        
//        let bgImgView = UIImageView(image: UIImage(named: "launch_screen_image"))
//        view.addSubview(bgImgView)
//        bgImgView.snp.makeConstraints { make in
//            make.edges.equalTo(self.view)
//        }
        
        view.addSubview(self.smsInputView)
        smsInputView.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(50)
            make.right.equalTo(self.view).offset(-50)
            make.top.equalTo(self.view.snp.top).offset(100)
            make.height.equalTo(60)
        }
          
//        let inputView = YHValidateCodeInputView(count: 6, inputWith: 40, inputHeight: 60, gap: 10)
//        view.addSubview(inputView)
//        inputView.snp.makeConstraints { make in
//            make.left.right.equalTo(self.view)
//            make.top.equalTo(self.view.snp.top).offset(100)
//            make.height.equalTo(100)
//        }
    }
    
}

extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: YHPersonalCenterCell.cellReuseIdentifier, for: indexPath) as! YHPersonalCenterCell
        let item : PersonalModuleItem = items[indexPath.row];
        cell.updateItem(item: item)
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = YHLoginViewController()
        self.navigationController?.pushViewController(vc)
    }
}
