//
//  YHBasicInfoFillViewController.swift
//  galaxy
//
//  Created by davidhuangA on 2024/2/3.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit
import GKNavigationBarSwift
/*
 基本资料信息填写
 */

class YHBasicInfoFillViewController: YHBaseViewController {
    var orderId : Int?
    private let basicInfoVM : YHBasicInfoFillViewModel = YHBasicInfoFillViewModel()
    var homeTableView: UITableView = {
        let tableView = UITableView(frame: .zero, style:.grouped)
        tableView.backgroundColor = .clear
        tableView.separatorStyle = .none
        tableView.showsHorizontalScrollIndicator = false
        tableView.showsVerticalScrollIndicator = false
        tableView.rowHeight = UITableView.automaticDimension
        tableView.register(YHBasicInfoFillCell.self,forCellReuseIdentifier: YHBasicInfoFillCell.cellReuseIdentifier)
        return tableView
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //1.0
        initView()
        
        //2.0
        loadData()
    }
}

// MARK: - private methods
extension YHBasicInfoFillViewController {
    private func initView() {
        gk_backStyle = .black
        gk_navTitle = "基本资料信息填写"
        gk_navBackgroundColor = .white
        gk_navBarAlpha = 1
        
        let bottomView = YHBasicInfoFillBottomView()
        view.addSubview(bottomView)
        bottomView.snp.makeConstraints { make in
            make.bottom.left.right.equalToSuperview()
            make.height.equalTo(YHBasicInfoFillBottomView.viewH)
        }
        
        bottomView.block = { tag in
            if tag == 0 {
                //点击了保存按钮
                printLog("点击了保存按钮")
                
            } else {
                //点击了提交按钮
                printLog("点击了提交按钮")
                
            }
            
        }
        
        
        homeTableView.delegate = self
        homeTableView.dataSource = self
        view.addSubview(homeTableView)
        homeTableView.snp.makeConstraints { make in
            make.top.equalTo(k_Height_NavigationtBarAndStatuBar + 15)
            make.bottom.equalTo(bottomView.snp.top)
            make.left.equalTo(kMargin)
            make.right.equalTo(-kMargin)
        }
    }
    
    
    private func loadData() {
        guard let orderId = orderId else { return}
        basicInfoVM.getBasicInfoData()
        homeTableView.reloadData()
//        let param = ["order_id":orderId]
//        serviceCenterMainReqVM.getMyScoreDetail(params: param) { success, error in
//            if success == true {
//                
//            } else {
//                YHHUD.flash(message: error?.errorMsg ?? "发生错误,请重试")
//            }
//            self.homeTableView.reloadData()
//        }
    }
    
}

// MARK: - delegates
// MARK: - UITableViewDelegate 和 UITableViewDataSource
extension YHBasicInfoFillViewController : UITableViewDelegate,UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return basicInfoVM.arrBasicInfoSessionDataForEdit.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 15
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 15))
        view.backgroundColor = .clear
        return view
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withClass: YHBasicInfoFillCell.self)
        cell.dataModel = basicInfoVM.arrBasicInfoSessionDataForEdit[indexPath.section]
        cell.indexPath = indexPath
        cell.block = { indexPath in
            if let indexPath = indexPath {
                tableView.reloadRows(at: [indexPath], with: .none)
            }
        }
        return cell
    }
}
