import SwiftUI

struct AllTVShowsRow: View {
    let shows: [TVShow]
    let onSeeAll: () -> Void
    let onSelectShow: (TVShow) -> Void
    @FocusState private var focusedItem: String?

    private var displayedShows: [TVShow] {
        Array(shows.prefix(Constants.TMDB.tvMaxDisplayCount))
    }

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

                Spacer()

                if shows.count > Constants.TMDB.tvMaxDisplayCount {
                    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(displayedShows) { show in
                        Button {
                            onSelectShow(show)
                        } label: {
                            TVShowCardView(
                                tvShow: show,
                                isFocused: focusedItem == show.id
                            )
                        }
                        .buttonStyle(.plain)
                        .focused($focusedItem, equals: show.id)
                    }
                }
                .padding(.horizontal, 80)
            }
        }
    }
}
