//
//  TableRowView.swift
//  iKeyMon
//
//  Created by tracer on 01.04.25.
//

import SwiftUI

struct TableRowView<Label: View, Value: View>: View {
    var showDivider: Bool = true
    @ViewBuilder let label: () -> Label
    @ViewBuilder let value: () -> Value

    var body: some View {
        VStack(spacing: 0) {
            HStack(alignment: .top) {
                label()
                    .frame(width: 180, alignment: .leading)
                    .unredacted()
                
                value()
                    .frame(maxWidth: .infinity, alignment: .leading)
            }
            .padding(.vertical, 2)
        }
        if showDivider {
            Divider()
                .opacity(0.6)
        }
    }
}

#Preview {
    TableRowView {
        Text("Label")
            .fontWeight(.semibold)
    } value: {
        HStack(spacing: 4) {
            Text("42%")
                .foregroundColor(.green)
                .fontWeight(.semibold)
            Text("(extra info)")
                .foregroundColor(.secondary)
                .font(.callout)
        }
    }
    .padding()
}
