//
//  MeterInfoCardView.swift
//  USB Meter
//

import SwiftUI

struct MeterInfoCardView<Content: View, TrailingActions: View>: View {
    let title: String
    let infoMessage: String?
    let tint: Color
    @ViewBuilder var trailingActions: TrailingActions
    @ViewBuilder var content: Content

    init(
        title: String,
        infoMessage: String? = nil,
        tint: Color,
        @ViewBuilder trailingActions: () -> TrailingActions = { EmptyView() },
        @ViewBuilder content: () -> Content
    ) {
        self.title = title
        self.infoMessage = infoMessage
        self.tint = tint
        self.trailingActions = trailingActions()
        self.content = content()
    }

    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            HStack(spacing: 8) {
                Text(title)
                    .font(.headline)
                if let infoMessage {
                    ContextInfoButton(title: title, message: infoMessage)
                }
                Spacer(minLength: 0)
                trailingActions
            }
            content
        }
        .frame(maxWidth: .infinity, alignment: .leading)
        .padding(18)
        .meterCard(tint: tint, fillOpacity: 0.18, strokeOpacity: 0.24)
    }
}
