//
//  ContentView.swift
//  swiftui-starter
//
//  Created by Ricardo Monteverde on 4/18/22.
//

import Combine
import SwiftUI
// import EnvironmentOverrides

// MARK: - View

struct ContentView: View {
    @ObservedObject private(set) var viewModel: ViewModel

    var body: some View {
        Group {
//            if viewModel.isRunningTests {
            Text("Running unit tests")
//            } else {
//                CountriesList(viewModel: .init(container: viewModel.container))
//                    .attachEnvironmentOverrides(onChange: viewModel.onChangeHandler)
//                    .modifier(RootViewAppearance(viewModel: .init(container: viewModel.container)))
//            }
        }
    }
}

// MARK: - ViewModel

extension ContentView {
    class ViewModel: ObservableObject {
        let container: DIContainer
        let isRunningTests: Bool

        init(container: DIContainer, isRunningTests: Bool = ProcessInfo.processInfo.isRunningTests) {
            self.container = container
            self.isRunningTests = isRunningTests
        }

//        var onChangeHandler: (EnvironmentValues.Diff) -> Void {
//            return { diff in
//                if !diff.isDisjoint(with: [.locale, .sizeCategory]) {
//                    self.container.appState[\.routing] = AppState.ViewRouting()
//                }
//            }
//        }
    }
}

// MARK: - Preview

#if DEBUG
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView(viewModel: ContentView.ViewModel(container: .preview))
        }
    }
#endif
