//
//  LocationsListCoordinator.swift
//  Locations
//
//  Created by Javier Cicchelli on 11/04/2023.
//  Copyright © 2023 Röck+Cöde. All rights reserved.
//

import Core
import UIKit

class LocationsListCoordinator: Coordinator {
    
    // MARK: Properties
    
    var children: [Coordinator] = []
    var router: Router
    
    private var viewController: UIViewController?
    
    // MARK: Initialisers
    
    init(router: Router) {
        self.router = router
    }
    
    // MARK: Coordinator
    
    func present(animated: Bool, onDismiss: (() -> Void)?) {
        let navigationController = UINavigationController(rootViewController: LocationsListViewController(
            viewModel: LocationsListViewModel(coordinator: self)
        ))
        
        viewController = navigationController
        
        router.present(
            navigationController,
            animated: animated,
            onDismiss: onDismiss
        )
    }
    
}

// MARK: - LocationsListCoordination

extension LocationsListCoordinator: LocationsListCoordination {
    
    // MARK: Functions
    
    func openAddLocation() {
        guard let viewController else {
            return
        }
        
        present(
            child: LocationsAddCoordinator(
                router: ModalNavigationRouter(parentViewController: viewController)
            ),
            animated: true
        )
    }
    
}
