//
//  QuickActionsBar.swift
//  lichunWebsocket
//
//  Pill-style action buttons for primary relationship actions
//

import SwiftUI

struct QuickActionsBar: View {
    let partner: Person
    let onDateTap: () -> Void
    let onGiftTap: () -> Void
    let onChatTap: () -> Void

    var body: some View {
        HStack(spacing: AppSpacing.md) {
            ActionPill(
                icon: "calendar.badge.clock",
                label: "Date",
                iconColor: AppColors.primary,
                action: onDateTap
            )

            ActionPill(
                icon: "gift.fill",
                label: "Gift",
                iconColor: AppColors.accent,
                action: onGiftTap
            )

            ActionPill(
                icon: "message.fill",
                label: "Chat",
                iconColor: AppColors.success,
                action: onChatTap
            )
        }
        .padding(.horizontal, AppSpacing.sm)
    }
}

// MARK: - Action Pill Subcomponent

private struct ActionPill: View {
    let icon: String
    let label: String
    let iconColor: Color
    let action: () -> Void

    var body: some View {
        Button(action: {
            hapticFeedback(style: .light)
            action()
        }) {
            HStack(spacing: AppSpacing.xs) {
                ZStack {
                    Circle()
                        .fill(iconColor.opacity(0.15))
                        .frame(width: 28, height: 28)

                    Image(systemName: icon)
                        .font(.system(size: 16))
                        .foregroundColor(iconColor)
                }

                Text(label)
                    .font(.appBody)
                    .foregroundColor(AppColors.primaryText)
            }
            .padding(.horizontal, AppSpacing.md)
            .padding(.vertical, AppSpacing.sm)
            .frame(height: 44)
            .background(
                ZStack {
                    AppColors.cardBackground

                    LinearGradient(
                        colors: [
                            iconColor.opacity(0.05),
                            Color.clear
                        ],
                        startPoint: .leading,
                        endPoint: .trailing
                    )
                }
            )
            .overlay(
                RoundedRectangle(cornerRadius: 22)
                    .stroke(iconColor.opacity(0.3), lineWidth: 1)
            )
            .cornerRadius(22)
            .shadow(color: iconColor.opacity(0.15), radius: 8, x: 0, y: 4)
        }
        .buttonStyle(SquishButtonStyle())
    }
}

// MARK: - Preview

#if DEBUG
struct QuickActionsBar_Previews: PreviewProvider {
    static var previews: some View {
        VStack(spacing: AppSpacing.xl) {
            // Normal state
            QuickActionsBar(
                partner: mockPartner(),
                onDateTap: { print("Date tapped") },
                onGiftTap: { print("Gift tapped") },
                onChatTap: { print("Chat tapped") }
            )

            // With different background to show contrast
            QuickActionsBar(
                partner: mockPartner(),
                onDateTap: { print("Date tapped") },
                onGiftTap: { print("Gift tapped") },
                onChatTap: { print("Chat tapped") }
            )
            .padding()
            .background(AppColors.primaryBackground.opacity(0.5))
        }
        .padding()
        .background(AppColors.primaryBackground)
    }

    static func mockPartner() -> Person {
        let person = Person()
        person.id = "partner123"
        person.firstname = "Sarah"
        person.lastname = "Johnson"
        return person
    }
}
#endif
