//
//  TabBarController.swift
//  WoWonder
//
//  Created by Mohammed Hamad on 19/07/2022.
//  Copyright © 2022 ScriptSun. All rights reserved.
//

import UIKit

class TabBarController: UITabBarController {
    
    // MARK: - Properties
    
    var selectedTabIndex = 0
    
    // MARK: - View Life Cycles
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        self.delegate = self
    }
    
}

// MARK: - Extensions

// MARK: UITabBarControllerDelegate Methods
extension TabBarController: UITabBarControllerDelegate {
    
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        self.selectedTabIndex = item.tag
    }
    
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        if self.selectedTabIndex == 2 {
            if let newVC = R.storyboard.dashboard.groupVC() {
                self.navigationController?.pushViewController(newVC, animated: true)
                return false
            } else {
                return true
            }
        } else if self.selectedTabIndex == 4 {
            if let newVC = R.storyboard.dashboard.settingsVC() {
                self.navigationController?.pushViewController(newVC, animated: true)
                return false
            } else {
                return true
            }
        } else {
            return true
        }
    }
    
}
