//
//  YHInformationPerfectListVC.swift
//  galaxy
//
//  Created by davidhuangA on 2024/1/25.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

/*
 *信息完善列表
 */
class YHInformationPerfectListVC: YHBaseViewController {
//    private let serviceCenterMainReqVM : YHServiceCenterMainViewModel = YHServiceCenterMainViewModel()

    
    var arrData : [YHInformationPerfectModel] = []
    private var myTargetIndex : Int32 = 1
    
    private lazy var topBkg : UIView = {
        let imagV = UIImageView()
        imagV.image = UIImage(named: "service_center_head_bkg")
        imagV.contentMode = .scaleAspectFill
        return imagV
        
    }()
    
    var homeTableView: UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.backgroundColor = .clear
        tableView.separatorStyle = .none
        tableView.showsHorizontalScrollIndicator = false
        tableView.showsVerticalScrollIndicator = false
        tableView.register(YHInformationPerfectCell.self,forCellReuseIdentifier: YHInformationPerfectCell.cellReuseIdentifier)
        return tableView
    }()
    
    var myHeadView : UIView = {
        let view = UIView()
        let titleLable = UILabel(text: "您好,黄先生")
        titleLable.font = kFont(size: 21)
        
        view.addSubview(titleLable)
        titleLable.snp.makeConstraints { make in
            make.top.equalTo(16)
            make.left.equalTo(24)
            make.right.equalTo(-24)
            make.height.equalTo(26)
        }
        
        let desLable = UILabel(text: "此表由主申请人填写，我们将会根据您的个人信息制作资料清单，请按顺序填写，提交后1-2个工作日内联系您哦~")
        desLable.font = kFont(size: 13)
        desLable.numberOfLines = 0
        desLable.lineBreakMode = .byWordWrapping
        
        view.addSubview(desLable)
        desLable.snp.makeConstraints { make in
            make.top.equalTo(titleLable.snp.bottom).offset(10)
            make.left.equalTo(24)
            make.right.equalTo(-24)
        }
        return view
    }()
    
    
    var myBottomView : UIView = {
        let view = UIView()
        view.backgroundColor = .white
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        loadData()
    }
    
}

extension YHInformationPerfectListVC {
    func loadData() {
//        self.serviceCenterMainReqVM.getContactList { success, error in
//            if success == true {
//
//            }
//            self.homeTableView.reloadData()
//        }
    }
    
    @objc func clickSubmitBtn() {
        YHSubmitAllInfoCheckView.showCheckView { agree in
            if agree == true {
                printLog("点击了 确认 按钮")
                
                YHSubmintAllInfoSuccessTipView.showCheckView { agree in
                    if agree == true {
                        printLog("点击了 确认2 按钮")
                    } else {
                        printLog("点击了 取消2 按钮")
                    }
                }
            } else {
                printLog("点击了 取消 按钮")
            }
        }
    }
    
    func setupUI() {
        gk_navTitle = "信息完善"
        gk_navBarAlpha = 1.0
        gk_navLineHidden = true
        
        
        let arr = [1,2,3,4,5,6]
        let target = myTargetIndex //for test hjl 待填写的项目
        for item in arr {
            let model = YHInformationPerfectModel()
            model.type = item
            arrData.append(model)
            
            if item < target {
                model.isFinished = true
            } else {
                model.isFinished = false
            }
            
            
            if item == target  {
                model.isDoing = true
            }
            
            
            if item == target + 1 {
                model.isNextDoingCell = true
            } else {
                model.isNextDoingCell = false
            }
        }
        
        
        view.addSubview(topBkg)
        topBkg.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(216)
        }
        
        
        view.addSubview(myBottomView)
        myBottomView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
            make.height.equalTo(84)
        }
        
        
        let submitBtn = UIButton(type: .custom)
        submitBtn.layer.opacity = 0.4
        submitBtn.setTitle("提交信息", for: .normal)
        submitBtn.setTitleColor(UIColor.white, for: .normal)
//        submitBtn.addGradualLayer([UIColor(hex: 0x2274EE, alpha: 1.0),UIColor(hex: 0x3A85FC, alpha: 1.0)])
        submitBtn.setBackgroundImage(UIImage.from(color: UIColor(hex: 0x4D9FF8, alpha: 1.0)), for: .normal)
        submitBtn.layer.cornerRadius = 8
        submitBtn.clipsToBounds = true
        myBottomView.addSubview(submitBtn)
        
        submitBtn.addTarget(self, action: #selector(clickSubmitBtn), for: .touchUpInside)
        submitBtn.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.height.equalTo(48)
        }
        
        
        homeTableView.delegate = self
        homeTableView.dataSource = self
        view.addSubview(homeTableView)
        homeTableView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
            make.bottom.equalTo(myBottomView.snp.top)
        }
        
        myHeadView.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 96)
        homeTableView.tableHeaderView = myHeadView
        homeTableView.reloadData()
    }
}

// MARK: - UITableViewDelegate 和 UITableViewDataSource
extension YHInformationPerfectListVC : UITableViewDelegate,UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 6
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return YHInformationPerfectCell.cellHeight
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let newCell = tableView.dequeueReusableCell(withClass: YHInformationPerfectCell.self)
        newCell.selectionStyle = .none
        newCell.dataModel = arrData[indexPath.row]
        return newCell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        printLog("点击了 \(indexPath.section)section  --- \(indexPath.row)row")
        let model = arrData[indexPath.row]
        if (indexPath.row + 1 > myTargetIndex) {
            let message = "请先完成" + model.name + "填写"
            YHHUD.flash(message: message)
        } else {
            navigationController?.pushViewController(YHMainApplicantInformationViewController())
        }
    }
}
