import SwiftUI

struct CategoryCardsRow: View {
    let categories: [Category]
    var title: String = "Browse Categories"
    let onSelect: (Category) -> Void
    @FocusState private var focusedCategory: String?

    var body: some View {
        VStack(alignment: .leading, spacing: 20) {
            Text(title)
                .font(.title2)
                .fontWeight(.bold)
                .foregroundColor(.white)
                .padding(.horizontal, 80)

            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 10) {
                    ForEach(categories) { category in
                        Button {
                            onSelect(category)
                        } label: {
                            CategoryCard(
                                category: category,
                                isFocused: focusedCategory == category.id
                            )
                        }
                        .buttonStyle(.plain)
                        .focused($focusedCategory, equals: category.id)
                    }
                }
                .padding(.horizontal, 80)
            }
        }
    }
}
