import SwiftUI

struct InsightsRow: View {
    let insights: [PortfolioInsight]

    var body: some View {
        VStack(alignment: .leading, spacing: 10) {
            Text(String(localized: "insights_section_title"))
                .font(.headline)

            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 12) {
                    ForEach(insights) { insight in
                        insightChip(insight)
                    }
                }
            }
        }
        .padding()
        .background(Color(.systemBackground))
        .cornerRadius(AppConstants.UI.cornerRadius)
        .shadow(color: .black.opacity(0.05), radius: 8, y: 2)
    }

    private func insightChip(_ insight: PortfolioInsight) -> some View {
        VStack(alignment: .leading, spacing: 4) {
            HStack(spacing: 5) {
                Image(systemName: insight.systemImage)
                    .font(.caption.weight(.semibold))
                    .foregroundColor(insight.accentColor)
                Text(insight.title)
                    .font(.caption2)
                    .foregroundColor(.secondary)
            }
            Text(insight.value)
                .font(.subheadline.weight(.semibold))
                .foregroundColor(.primary)
                .lineLimit(1)
        }
        .padding(.horizontal, 14)
        .padding(.vertical, 10)
        .background(insight.accentColor.opacity(0.08))
        .cornerRadius(12)
        .overlay(
            RoundedRectangle(cornerRadius: 12)
                .stroke(insight.accentColor.opacity(0.2), lineWidth: 1)
        )
    }
}
