//
//  HintViews.swift
//  Blackjack
//
//  Views for displaying game hints and betting recommendations.
//

import SwiftUI
import CasinoKit

// MARK: - General Hint View

/// Displays a gameplay hint (hit, stand, double, etc.)
struct HintView: View {
    let hint: String
    
    @ScaledMetric(relativeTo: .body) private var iconSize: CGFloat = Design.Size.hintIconSize
    @ScaledMetric(relativeTo: .body) private var fontSize: CGFloat = Design.Size.hintFontSize
    @ScaledMetric(relativeTo: .body) private var paddingH: CGFloat = Design.Size.hintPaddingH
    @ScaledMetric(relativeTo: .body) private var paddingV: CGFloat = Design.Size.hintPaddingV
    
    var body: some View {
        HStack(spacing: Design.Spacing.small) {
            Image(systemName: "lightbulb.fill")
                .font(.system(size: iconSize))
                .foregroundStyle(.yellow)
            Text(hint)
                .font(.system(size: fontSize, weight: .medium))
                .foregroundStyle(.white)
                .lineLimit(1)
                .minimumScaleFactor(Design.MinScaleFactor.comfortable)
        }
        .padding(.horizontal, paddingH)
        .padding(.vertical, paddingV)
        .frame(minWidth: Design.Size.hintMinWidth, alignment: .leading)
        .background(
            Capsule()
                .fill(Color.black.opacity(Design.Opacity.heavy))
                .overlay(
                    Capsule()
                        .strokeBorder(Color.yellow.opacity(Design.Opacity.medium), lineWidth: Design.LineWidth.thin)
                )
        )
        .shadow(color: .black.opacity(Design.Opacity.medium), radius: Design.Shadow.radiusMedium)
        .accessibilityElement(children: .ignore)
        .accessibilityLabel(String(localized: "Hint"))
        .accessibilityValue(hint)
    }
}

// MARK: - Blackjack Betting Hint View

/// Shows betting recommendations based on the current card count.
/// Maps true count to hint style and uses CasinoKit's shared BettingHintView.
struct BlackjackBettingHintView: View {
    let hint: String
    let trueCount: Double
    
    /// Determines the hint style based on true count.
    private var style: BettingHintStyle {
        let tc = Int(trueCount.rounded())
        if tc >= 2 {
            return .positive  // Player advantage - bet more
        } else if tc <= -1 {
            return .negative  // House advantage - bet less
        } else {
            return .neutral   // Neutral
        }
    }
    
    var body: some View {
        BettingHintView(hint: hint, style: style)
    }
}

// MARK: - Previews

#Preview("Game Hint - Hit") {
    ZStack {
        Color.Table.felt.ignoresSafeArea()
        HintView(hint: "Hit")
    }
}

#Preview("Game Hint - Stand") {
    ZStack {
        Color.Table.felt.ignoresSafeArea()
        HintView(hint: "Stand")
    }
}

#Preview("Betting Hint - Positive Count") {
    ZStack {
        Color.Table.felt.ignoresSafeArea()
        BlackjackBettingHintView(hint: "Bet 4x minimum", trueCount: 2.5)
    }
}

#Preview("Betting Hint - Negative Count") {
    ZStack {
        Color.Table.felt.ignoresSafeArea()
        BlackjackBettingHintView(hint: "Bet minimum", trueCount: -1.5)
    }
}

#Preview("Betting Hint - Neutral") {
    ZStack {
        Color.Table.felt.ignoresSafeArea()
        BlackjackBettingHintView(hint: "Bet minimum (neutral)", trueCount: 0.0)
    }
}

