//
//  ContentMainSeriesGenreView.swift
//  SodaLive
//
//  Created by klaus on 2/21/25.
//

import SwiftUI

struct ContentMainSeriesGenreView: View {
    let genreList: [GetSeriesGenreListResponse]
    let selectGenre: (Int) -> Void
    
    @Binding var selectedGenreId: Int
    
    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack(alignment: .top, spacing: 8) {
                ForEach(0..<genreList.count, id: \.self) { index in
                    let genre = genreList[index]
                    Text(genre.genre)
                        .font(.custom(Font.medium.rawValue, size: 14.7))
                        .foregroundColor(selectedGenreId == genre.id ? Color.button : Color.gray77)
                        .padding(.horizontal, 13.3)
                        .padding(.vertical, 9.3)
                        .border(
                            selectedGenreId == genre.id ? Color.button : Color.grayee,
                            width: 1
                        )
                        .cornerRadius(16.7)
                        .overlay(
                            RoundedRectangle(cornerRadius: CGFloat(16.7))
                                .stroke(lineWidth: 1)
                                .foregroundColor(selectedGenreId == genre.id ? Color.button : Color.grayee)
                        )
                        .onTapGesture {
                            if selectedGenreId != genre.id {
                                selectGenre(genre.id)
                            }
                        }
                }
            }
            .padding(.horizontal, 13.3)
        }
    }
}

#Preview {
    ContentMainSeriesGenreView(
        genreList: [
            GetSeriesGenreListResponse(id: 1, genre: "test"),
            GetSeriesGenreListResponse(id: 2, genre: "test2"),
            GetSeriesGenreListResponse(id: 3, genre: "test3")
        ],
        selectGenre: { _ in },
        selectedGenreId: .constant(2)
    )
}
