//
//  MenuCoordinator.swift
//  1Weather
//
//  Created by Dmitry Stepanets on 25.03.2021.
//

import UIKit

class MenuCoordinator: Coordinator {
    //Private
    private let menuViewModel = MenuViewModel()
    private let navigationController = UINavigationController(nibName: nil, bundle: nil)
    private var tabBarController:UITabBarController?
    
    //Public
    var childCoordinators = [Coordinator]()
    var parentCoordinator: Coordinator?
    
    init(tabBarController:UITabBarController) {
        self.tabBarController = tabBarController
    }
    
    func start() {
        let menuViewController = MenuViewController(coordinator: self, menuViewModel: menuViewModel)
        navigationController.viewControllers = [menuViewController]
        tabBarController?.add(viewController: navigationController)
    }
    
    func viewControllerDidEnd(controller: UIViewController) {
        parentCoordinator?.childDidFinish(child: self)
    }
    
    func openSettings() {
        let settingsCoordinator = SettingsCoordinator(parentViewController: self.navigationController)
        settingsCoordinator.parentCoordinator = self
        childCoordinators.append(settingsCoordinator)
        settingsCoordinator.start()
    }
}
