//
//  HandValueBadge.swift
//  Baccarat
//
//  A capsule badge displaying the hand value.
//  Matches CasinoKit's ValueBadge styling for consistency with Blackjack.
//

import SwiftUI
import CasinoKit

/// A capsule badge showing the hand value.
/// Uses the same styling as CasinoKit's ValueBadge for consistency across games.
struct HandValueBadge: View {
    let value: Int
    let color: Color
    
    // MARK: - Scaled Metrics (Dynamic Type)
    // These match CasinoKit's ValueBadge exactly
    
    @ScaledMetric(relativeTo: .headline) private var valueFontSize: CGFloat = 15
    @ScaledMetric(relativeTo: .headline) private var badgeHeight: CGFloat = CasinoDesign.Size.valueBadge
    @ScaledMetric(relativeTo: .headline) private var badgePadding: CGFloat = 8
    
    // MARK: - Body
    
    var body: some View {
        Text("\(value)")
            .font(.system(size: valueFontSize, weight: .black, design: .rounded))
            .foregroundStyle(.white)
            .lineLimit(1)
            .fixedSize(horizontal: true, vertical: false)
            .padding(.horizontal, badgePadding)
            .frame(minWidth: badgeHeight, minHeight: badgeHeight)
            .background(
                Capsule()
                    .fill(color)
            )
    }
}

// MARK: - Previews

#Preview("Player Value (Blue)") {
    ZStack {
        Color.Table.backgroundDark
        HandValueBadge(value: 8, color: .blue)
    }
}

#Preview("Banker Value (Red)") {
    ZStack {
        Color.Table.backgroundDark
        HandValueBadge(value: 5, color: .red)
    }
}

#Preview("Natural 9") {
    ZStack {
        Color.Table.backgroundDark
        HandValueBadge(value: 9, color: .blue)
    }
}

#Preview("Zero Value") {
    ZStack {
        Color.Table.backgroundDark
        HandValueBadge(value: 0, color: .red)
    }
}

