//
//  DataGroupView.swift
//  USB Meter
//
//  Created by Bogdan Timofte on 10/03/2020.
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
//
// https://www.youtube.com/watch?v=9q209mNDV_4

import SwiftUI

struct DataGroupRowView: View {
    
    var id: UInt8
    var width: CGFloat
    var opacity: Double
    
    @EnvironmentObject private var usbMeter: Meter
    
    var body: some View {
        HStack (spacing: 1) {
            ZStack {
                Button(action: { self.usbMeter.selectDataGroup( id: self.id ) }, label: { Image(systemName: "\(id).circle") })//.font(.title)
                Rectangle().opacity( opacity )
            }.frame(width: width)
            
            ZStack {
                Text("\(usbMeter.dataGroupRecords[Int(id)]!.ah.format(decimalDigits: 3))")
                Rectangle().opacity( opacity )
            }.frame(width: width)
            
            ZStack {
                Text("\(usbMeter.dataGroupRecords[Int(id)]!.wh.format(decimalDigits: 3))")
                Rectangle().opacity( opacity )
            }.frame(width: width)
            
            ZStack {
                Button(action: { self.usbMeter.clear(group: self.id) }, label: { Image(systemName: "bin.xmark") })
//                    .font(.title)
//                    .foregroundColor(.red)
                Rectangle().opacity( opacity )
            }.frame(width: width)
        }
        .background(BorderView(show: usbMeter.selectedDataGroup == id))
    }
}
