//
//  SettingsCoordinator.swift
//  1Weather
//
//  Created by Dmitry Stepanets on 26.03.2021.
//

import UIKit

class SettingsCoordinator: Coordinator {
    //Private
    private let settingsViewModel = SettingsViewModel()
    private let navVC = UINavigationController()
    private var parentViewController:UIViewController?
    
    //Public
    var childCoordinators = [Coordinator]()
    var parentCoordinator: Coordinator?
    
    init(parentViewController:UIViewController) {
        self.parentViewController = parentViewController
    }
    
    func start() {
        DispatchQueue.main.async {
            let settingsViewController = SettingsViewController(coordinator: self, settingsViewModel: self.settingsViewModel)
            self.navVC.setViewControllers([settingsViewController], animated: false)
            self.parentViewController?.present(self.navVC, animated: true)
        }
    }
    
    func openDetailsViewController(rowType:SettingsRow) {
        let detailsCoordinator = SettingsDetailsCoordinator(navigationController: self.navVC, settingsRow: rowType)
        detailsCoordinator.parentCoordinator = self
        childCoordinators.append(detailsCoordinator)
        detailsCoordinator.start()
    }
    
    func viewControllerDidEnd(controller: UIViewController) {
        
    }
}
