//
//  YHSpouseInfoVC.swift
//  galaxy
//
//  Created by edy on 2024/1/31.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHSpouseInfoVC: YHBaseViewController {

    var spouse:YHFamilyMember? {
        didSet {
            initalInfoVC.spouse = spouse
            passportInfoVC.familyMember = spouse
            basicInfoVC.spouse = spouse
        }
    }
    
    var currentIndex = 0 {
        didSet {
            currentIndex %= 4
            stepView.currentIndex = currentIndex
            for (i, vc) in self.children.enumerated() {
                vc.view.isHidden = (currentIndex != i)
                if currentIndex == i {
                    
                }
            }
        }
    }
    
    var stepView:YHStepView = {
        let step = YHStepView()
        step.dataSource = ["初始信息", "证件上传", "基本信息", "证件信息"]
        step.block = {  (index) in
//            guard let self = self else { return }
            
        }
        return step
    }()
    
    var bottomView: YHSaveAndSubmitView = {
        return YHSaveAndSubmitView.createView()
    }()
        
    let initalInfoVC =  YHSpouseInitialInfoVC()
    let uploadVC = UIViewController()
    let passportInfoVC = YHCertificateViewController()
    let basicInfoVC = YHSpouseBasicInfoVC()

    override func viewDidLoad() {
        super.viewDidLoad()
        createUI()
    }
    
    func createUI() {
                
        self.addChild(initalInfoVC)
        self.addChild(uploadVC)
        self.addChild(passportInfoVC)
        self.addChild(basicInfoVC)
        
        self.view.addSubview(basicInfoVC.view)
        self.view.addSubview(passportInfoVC.view)
        self.view.addSubview(uploadVC.view)
        self.view.addSubview(initalInfoVC.view)

        currentIndex = 0
        
        view.addSubview(stepView)
        view.addSubview(bottomView)
        
        bottomView.submitBlock = {
            [weak self] in
            guard let self = self else { return }
            self.didClickSubmitBtn()
        }
        
        bottomView.saveBlock = {
            [weak self] in
            guard let self = self else { return }
            self.didClickSaveBtn()
        }
        
        stepView.snp.makeConstraints { make in
            make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
            make.left.right.equalTo(view)
            make.height.equalTo(YHStepView.height)
        }
        
        bottomView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-k_Height_safeAreaInsetsBottom())
            make.height.equalTo(YHSaveAndSubmitView.height)
        }
    }
    
    func didClickSubmitBtn() {
        currentIndex += 1;
        
    }
    
    func didClickSaveBtn() {
        
    }
}
