//
//  CurrenciesCoordinator.swift
//  IlgonWallet
//
//  Created by Jili Bernadett on 2021. 04. 01..
//

import UIKit

protocol CurrenciesCoordinatorDelegate: class {
    func didSelect(currency: Currency, in coordinator: CurrenciesCoordinator)
}

class CurrenciesCoordinator: Coordinator {
    var coordinators: [Coordinator] = []

    lazy var currenciesViewController: CurrenciesViewController = {
        let currencies: [Currency] = [
            .USD,
            .EUR,
            .GBP,
            .HUF,
            .AUD,
            .CNY,
            .INR,
            .SGD,
            .JPY,
            .KRW,
            .RUB
        ]
        let controller = CurrenciesViewController()
        controller.configure(viewModel: CurrenciesViewModel(currencies: currencies, selectedCurrency: getCurrency()))
        controller.delegate = self
        controller.hidesBottomBarWhenPushed = true
        return controller
    }()
    weak var delegate: CurrenciesCoordinatorDelegate?

    func start() {
    }
}

extension CurrenciesCoordinator: CurrenciesViewControllerDelegate {
    func didSelect(currency: Currency, in viewController: CurrenciesViewController) {
        setCurrency(currency)
        delegate?.didSelect(currency: currency, in: self)
    }
}

