import SwiftUI
import ComposeApp

struct ContractorCard: View {
    let contractor: ContractorSummary
    let onToggleFavorite: () -> Void

    var body: some View {
        HStack(spacing: AppSpacing.md) {
            // Avatar
//            ZStack {
//                Circle()
//                    .fill(Color.appPrimary.opacity(0.1))
//                    .frame(width: 56, height: 56)
//
//                Image(systemName: "person.fill")
//                    .font(.title2)
//                    .foregroundColor(Color.appPrimary)
//            }

            // Content
            VStack(alignment: .leading, spacing: AppSpacing.xxs) {
                // Name with favorite star
                HStack(spacing: AppSpacing.xxs) {
                    Text(contractor.name)
                        .font(.title3.weight(.semibold))
                        .foregroundColor(Color.appTextPrimary)
//                        .lineLimit(1)

                    if contractor.isFavorite {
                        Image(systemName: "star.fill")
                            .font(.caption)
                            .foregroundColor(Color.appAccent)
                    }
                }

                // Company
                if let company = contractor.company {
                    Text(company)
                        .font(.body)
                        .foregroundColor(Color.appTextSecondary)
//                        .lineLimit(1)
                }

                // Info row
                HStack(spacing: AppSpacing.sm) {
                    // Specialties (show first one if available)
                    if let firstSpecialty = contractor.specialties.first {
                        Label(firstSpecialty.name, systemImage: "wrench.and.screwdriver")
                            .font(.caption.weight(.medium))
                            .foregroundColor(Color.appTextSecondary)
                    }

                    // Rating
                    if let rating = contractor.rating, rating.doubleValue > 0 {
                        Label(String(format: "%.1f", rating.doubleValue), systemImage: "star.fill")
                            .font(.caption.weight(.medium))
                            .foregroundColor(Color.appAccent)
                    }

                    // Task count
                    if contractor.taskCount > 0 {
                        Label("\(contractor.taskCount) tasks", systemImage: "checkmark.circle")
                            .font(.caption.weight(.medium))
                            .foregroundColor(Color.appPrimary)
                    }
                }
            }

            Spacer()

            // Favorite button
            Button(action: onToggleFavorite) {
                Image(systemName: contractor.isFavorite ? "star.fill" : "star")
                    .font(.title3)
                    .foregroundColor(contractor.isFavorite ? Color.appAccent : Color.appTextSecondary.opacity(0.7))
            }
            .buttonStyle(PlainButtonStyle())
            .accessibilityLabel(contractor.isFavorite ? "Remove \(contractor.name) from favorites" : "Add \(contractor.name) to favorites")

            // Chevron
            Image(systemName: "chevron.right")
                .font(.caption)
                .foregroundColor(Color.appTextSecondary.opacity(0.7))
                .accessibilityHidden(true)
        }
        .padding(AppSpacing.md)
        .background(Color.appBackgroundSecondary)
        .cornerRadius(AppRadius.lg)
        .shadow(color: AppShadow.sm.color, radius: AppShadow.sm.radius, x: AppShadow.sm.x, y: AppShadow.sm.y)
    }
}
