import SwiftUI

struct AnimationTestingCard: View {
    let task: TestTask
    let onComplete: () -> Void

    var body: some View {
        VStack(alignment: .leading, spacing: AppSpacing.sm) {
            // Header with title and priority
            HStack(alignment: .top) {
                Text(task.title)
                    .font(.system(size: 16, weight: .bold, design: .rounded))
                    .foregroundColor(Color.appTextPrimary)
                    .lineLimit(2)

                Spacer()

                priorityBadge
            }

            // Description
            if let description = task.description {
                Text(description)
                    .font(.system(size: 13, weight: .medium))
                    .foregroundColor(Color.appTextSecondary)
                    .lineLimit(2)
            }

            // Metadata pills
            HStack(spacing: AppSpacing.sm) {
                metadataPill(icon: "repeat", text: task.frequency)
                Spacer()
                metadataPill(icon: "calendar", text: task.dueDate)
            }

            // Complete button
            Button(action: onComplete) {
                HStack(spacing: 6) {
                    Image(systemName: "checkmark.circle.fill")
                        .font(.system(size: 14, weight: .semibold))
                    Text("Complete")
                        .font(.system(size: 14, weight: .semibold, design: .rounded))
                }
                .frame(maxWidth: .infinity)
                .padding(.vertical, AppSpacing.sm)
                .foregroundColor(Color.appTextOnPrimary)
                .background(Color.appPrimary)
                .cornerRadius(AppRadius.md)
            }
            .buttonStyle(.plain)
        }
        .padding(AppSpacing.md)
        .background(Color.appBackgroundSecondary)
        .cornerRadius(AppRadius.lg)
        .shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 2)
    }

    private var priorityBadge: some View {
        Text(task.priority.rawValue)
            .font(.system(size: 10, weight: .bold, design: .rounded))
            .foregroundColor(.white)
            .padding(.horizontal, 8)
            .padding(.vertical, 4)
            .background(task.priority.color)
            .cornerRadius(AppRadius.sm)
    }

    private func metadataPill(icon: String, text: String) -> some View {
        HStack(spacing: 4) {
            Image(systemName: icon)
                .font(.system(size: 10))
            Text(text)
                .font(.system(size: 11, weight: .medium, design: .rounded))
        }
        .foregroundColor(Color.appTextSecondary)
        .padding(.horizontal, 8)
        .padding(.vertical, 4)
        .background(Color.appBackgroundPrimary.opacity(0.6))
        .cornerRadius(AppRadius.sm)
    }
}

// MARK: - Preview

#Preview {
    ZStack {
        Color.appBackgroundPrimary.ignoresSafeArea()

        VStack(spacing: 16) {
            AnimationTestingCard(task: TestTask.samples[0]) {
                print("Complete tapped")
            }

            AnimationTestingCard(task: TestTask.samples[1]) {
                print("Complete tapped")
            }
        }
        .padding()
    }
}
