//
//  LiveView.swift
//  USB Meter
//
//  Created by Bogdan Timofte on 09/03/2020.
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
//

import SwiftUI

struct LiveView: View {
    
    @EnvironmentObject private var meter: Meter

    var body: some View {
        VStack {
            Text("Live Data")
                .font(.headline)
            HStack {
                VStack (alignment: .leading) {
                    Text("Voltage:")
                    Text("Current:")
                    Text("Power:")
                    Text("Load")
                    Text("Temperature:")
                    Text("")
                    Text("USB Data+:")
                    Text("USB Data-:")
                    Text("Charger:")
                }
                VStack (alignment: .trailing) {
                    HStack {
                        Text("\(meter.measurements.voltage.context.minValue.format(decimalDigits: 3))V")
                        Text("\(meter.voltage.format(decimalDigits: 3))V")
                        Text("\(meter.measurements.voltage.context.maxValue.format(decimalDigits: 3))V")
                    }
                    HStack {
                        Text("\(meter.measurements.current.context.minValue.format(decimalDigits: 3))A")
                        Text("\(meter.current.format(decimalDigits: 3))A")
                        Text("\(meter.measurements.current.context.maxValue.format(decimalDigits: 3))A")
                    }
                    HStack {
                        Text("\(meter.measurements.power.context.minValue.format(decimalDigits: 3))W")
                        Text("\(meter.power.format(decimalDigits: 3))W")
                        Text("\(meter.measurements.power.context.maxValue.format(decimalDigits: 3))W")
                    }
                    Text("\(meter.loadResistance.format(decimalDigits: 1))Ω")
                    Text("\(meter.temperatureCelsius)℃")
                    Text("\(meter.temperatureFahrenheit)℉")
                    Text("\(meter.usbPlusVoltage.format(decimalDigits: 2))V")
                    Text("\(meter.usbMinusVoltage.format(decimalDigits: 2))V")
                    Text("\(meter.chargerTypeIndex)")
                }
            }
            .font(.footnote)
        }
    }
}
