//
//  MeasurementView.swift
//  USB Meter
//
//  Created by Bogdan Timofte on 13/04/2020.
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
//

import SwiftUI

struct MeasurementPointView: View {
    
    var power: Measurements.Measurement.Point
    var voltage: Measurements.Measurement.Point
    var current: Measurements.Measurement.Point

    @State var showDetail: Bool = false
    
    var body: some View {
        VStack {
            HStack {
                Image(systemName: "pencil.and.ellipsis.rectangle")
                    .imageScale(.large)
                Text ("\(voltage.timestamp.format(as: "yyyy-MM-dd hh:mm:ss"))")
                Spacer()
                Button(action: {
                    self.showDetail.toggle()
                }) {
                    Image(systemName: "chevron.right.circle")
                        .imageScale(.large)
                        .rotationEffect(.degrees(showDetail ? 90 : 0))
                        .animation(.easeInOut(duration: 0.25), value: showDetail)
                }
            }
            if showDetail {
                VStack {
                    HStack {
                        Text("Power:")
                        Spacer()
                        Text("\(power.value.format(fractionDigits: 4))")
                    }
                    HStack {
                        Text("Voltage:")
                        Spacer()
                        Text("\(voltage.value.format(fractionDigits: 4))")
                    }
                    HStack {
                        Text("Current:")
                        Spacer()
                        Text("\(current.value.format(fractionDigits: 4))")
                    }
                }
                .padding()
            }
        }
        
    }
}
