//
//  DetailView.swift
//  Covid-19 Tracker
//
//  Created by Brian Alberta on 4/18/20.
//  Copyright © 2020 Brian Alberta. All rights reserved.
//

import SwiftUI

struct CaseDetailView: View {
    @ObservedObject var viewModel: CaseDetailViewModel
    
    var body: some View {
        
        ActivityIndicatorView(isDisplayed: $viewModel.loading) {
            VStack {
                HStack {
                    Text("Region:")
                        .font(.headline)
                    Spacer()
                    Text("\(self.viewModel.data.region ?? "")")
                        .fontWeight(.thin)
                }
                HStack {
                    Text("Confirmed Cases: ")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.confirmed ?? 0)")
                        .fontWeight(.bold)
                        .foregroundColor(.red)
                }
                HStack {
                    Text("Deaths: ")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.deaths ?? 0)")
                        .fontWeight(.thin)
                        .foregroundColor(.red)
                }
                HStack {
                    Text("Mortality Rate: ")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.mortalityRate ?? 0)")
                        .fontWeight(.thin)
                        .foregroundColor(.red)
                }
                HStack {
                    Text("Incident Rate: ")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.incidentRate ?? 0.0)")
                        .fontWeight(.thin)
                        .foregroundColor(.primary)
                }
                HStack {
                    Text("People Tested: ")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.tested ?? 0)")
                        .fontWeight(.thin)
                        .foregroundColor(.primary)
                }
                HStack {
                    Text("Testing Rate: ")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.testingRate ?? 0.0)")
                        .fontWeight(.thin)
                        .foregroundColor(.primary)
                }
                HStack {
                    Text("Hospitalized")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.hospitalized ?? 0)")
                        .fontWeight(.thin)
                        .foregroundColor(.blue)
                }
                HStack {
                    Text("Hospitalization Rate")
                        .font(.subheadline)
                    Spacer()
                    Text("\(self.viewModel.data.hospitalizationRate ?? 0.0)")
                        .fontWeight(.thin)
                        .foregroundColor(.blue)
                }
            }.padding(EdgeInsets(top: 0, leading: 16.0, bottom: 0, trailing: 16.0))
        }.onAppear(perform: log)
    }
    
    func log() {
        print("View is loading.")
    }
}

struct DetailView_Previews: PreviewProvider {
    static var previews: some View {
        CaseDetailView(viewModel: CaseDetailViewModel(province: "Ohio"))
    }
}
