//
//  CozyActivityButton.swift
//  lichunWebsocket
//
//  Card-style activity button with energy cost badge
//

import SwiftUI

struct CozyActivityButton: View {
    let title: String
    let icon: String
    let color: Color
    let energyCost: Int
    let hasEnergy: Bool
    let action: () -> Void

    var body: some View {
        Button(action: {
            if hasEnergy {
                hapticFeedback(style: .medium)
                action()
            }
        }) {
            VStack(spacing: AppSpacing.sm) {
                // Icon circle
                ZStack {
                    Circle()
                        .fill(
                            LinearGradient(
                                colors: [
                                    color.opacity(0.2),
                                    color.opacity(0.15)
                                ],
                                startPoint: .topLeading,
                                endPoint: .bottomTrailing
                            )
                        )
                        .frame(width: 70, height: 70)

                    Image(systemName: icon)
                        .font(.system(size: 32, weight: .semibold))
                        .foregroundColor(color)
                }

                // Title
                Text(title)
                    .font(.system(size: 15, weight: .semibold, design: .rounded))
                    .foregroundColor(AppColors.primaryText)
                    .multilineTextAlignment(.center)
                    .lineLimit(2)

                // Energy cost badge
                HStack(spacing: 4) {
                    Image(systemName: "bolt.fill")
                        .font(.system(size: 10))
                    Text("\(energyCost)")
                        .font(.system(size: 12, weight: .bold, design: .rounded))
                }
                .foregroundColor(hasEnergy ? AppColors.energy : AppColors.error)
                .padding(.horizontal, 10)
                .padding(.vertical, 4)
                .background(
                    (hasEnergy ? AppColors.energy : AppColors.error).opacity(0.15)
                )
                .cornerRadius(12)
            }
            .padding(AppSpacing.md)
            .frame(maxWidth: .infinity)
            .background(AppColors.surfaceElevated)
            .cornerRadius(AppSpacing.cornerRadius)
            .overlay(
                RoundedRectangle(cornerRadius: AppSpacing.cornerRadius)
                    .strokeBorder(color.opacity(0.3), lineWidth: 2)
            )
            .shadow(
                color: Color.black.opacity(0.06),
                radius: AppSpacing.Shadow.radiusMedium,
                x: 0,
                y: AppSpacing.Shadow.offsetY
            )
            .shadow(
                color: Color.black.opacity(0.03),
                radius: 2,
                x: 0,
                y: 2
            )
            .opacity(hasEnergy ? 1.0 : 0.6)
        }
        .buttonStyle(SquishButtonStyle())
        .disabled(!hasEnergy)
    }
}

// MARK: - Preview
#if DEBUG
struct CozyActivityButton_Previews: PreviewProvider {
    static var previews: some View {
        HStack(spacing: 16) {
            CozyActivityButton(
                title: "Study Math",
                icon: "book.fill",
                color: AppColors.intelligence,
                energyCost: 10,
                hasEnergy: true
            ) {
                print("Study tapped")
            }

            CozyActivityButton(
                title: "Go to Gym",
                icon: "figure.run",
                color: AppColors.health,
                energyCost: 15,
                hasEnergy: false
            ) {
                print("Gym tapped")
            }
        }
        .padding()
        .background(AppColors.background)
    }
}
#endif
