import SwiftUI

struct FeaturedCategoryRow: View {
    let category: Category
    let movies: [VODItem]
    var releaseDates: [String: String] = [:]  // VODItem.id -> "YYYY-MM-DD"
    let onSeeAll: () -> Void
    let onSelectMovie: (VODItem) -> Void
    @FocusState private var focusedItem: String?

    private var displayedMovies: [VODItem] {
        Array(movies.prefix(10))
    }

    var body: some View {
        VStack(alignment: .leading, spacing: 20) {
            HStack {
                Text(category.name)
                    .font(.title2)
                    .fontWeight(.bold)
                    .foregroundColor(.white)

                Spacer()

                if movies.count > 10 {
                    Button {
                        onSeeAll()
                    } label: {
                        HStack(spacing: 8) {
                            Text("See All")
                            Image(systemName: "chevron.right")
                        }
                        .font(.callout)
                        .foregroundColor(.gray)
                    }
                    .buttonStyle(.plain)
                }
            }
            .padding(.horizontal, 80)

            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 10) {
                    ForEach(displayedMovies) { movie in
                        Button {
                            onSelectMovie(movie)
                        } label: {
                            VODCardView(
                                vodItem: movie,
                                isFocused: focusedItem == movie.id,
                                releaseDate: releaseDates[movie.id]
                            )
                        }
                        .buttonStyle(.plain)
                        .focused($focusedItem, equals: movie.id)
                    }
                }
                .padding(.horizontal, 80)
            }
        }
    }
}
