import Foundation
import UIKit

/// bottom tab view controller
class TabViewController: UITabBarController {
    
    private let jednotkyVC = UINavigationController(rootViewController: JednotkyViewController(viewModel: JednotkaViewModel(id: UserDefaults.unitId ?? "", first: true)))
    private let osobyVC = UINavigationController(rootViewController: OsobyViewController())
    private let STSVC = UINavigationController(rootViewController: STSViewController())
    private let profileVC = UINavigationController(rootViewController: ProfileViewController())
    
    /// initialization function
    init() {
        super.init(nibName: nil, bundle: nil)
        configureTabItems()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
    }
    
    /// function that configures items and adds them to the tab view controller
    private func configureTabItems() {
        let item1 = UITabBarItem()
        item1.image = UIImage(named: "profile")
        item1.title = "Profil"
        let item2 = UITabBarItem()
        item2.image = UIImage(named: "flag")
        item2.title = "Jednotky"
        let item3 = UITabBarItem()
        item3.image = UIImage(named: "people")
        item3.title = "Osoby"
        let item4 = UITabBarItem()
        item4.image = UIImage(named: "phone")
        item4.title = "STS"
        profileVC.tabBarItem = item1
        jednotkyVC.tabBarItem = item2
        osobyVC.tabBarItem = item3
        STSVC.tabBarItem = item4
        viewControllers = [profileVC, jednotkyVC, osobyVC, STSVC]
        selectedIndex = 2
        tabBar.tintColor = scoutOrange
        tabBar.unselectedItemTintColor = scoutBlue
    }
}
