//
//  LinkedChildVC.swift
//  WOKA
//
//  Created by MacBook Pro on 09/05/24.
//

import UIKit

class LinkedChildVC: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var nextBtn: LocalisedElementsButton!
    
    var vm = LinkedChildVM()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        vm.vc = self
        vm.initView()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(false, animated: animated)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(true, animated: animated)
        
//        if self.isMovingFromParent {
//            // Back button was pressed
//            PersistentStorage.shared.addOthersCount()
//        }
    }

    @IBAction func nextBtnTapped(_ sender: LocalisedElementsButton) {
        PersistentStorage.shared.addOthersCount()
        let sb = UIStoryboard(name: K.StoryBoard.authenticationSB, bundle: nil)
        let vc = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Authentication.userDetailsRegisterVC) as! UserDetailsRegisterVC
        self.navigationController?.pushViewController(vc, animated: true)
    }

}

// MARK: - TableView

extension LinkedChildVC : TableViewSRC{
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return vm.linkedChilds.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: K.CellIdentifier.Authentication.linkedChildCell, for: indexPath) as! LinkedChildCell
        cell.setData(data: vm.linkedChilds[indexPath.row])
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(indexPath.row)
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }
}
