//
//  ContentListCategoryView.swift
//  SodaLive
//
//  Created by klaus on 2/7/24.
//

import SwiftUI

struct ContentListCategoryView: View {
    let categoryList: [GetCategoryListResponse]
    let selectCategory: (Int) -> Void
    
    @Binding var selectedCategory: String
    
    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack(spacing: 8) {
                ForEach(0..<categoryList.count, id: \.self) { index in
                    let category = categoryList[index]
                    Text(category.category)
                        .font(.custom(Font.medium.rawValue, size: 14.7))
                        .foregroundColor(Color(hex: selectedCategory == category.category ? "3bb9f1" : "777777"))
                        .padding(.horizontal, 13.3)
                        .padding(.vertical, 9.3)
                        .border(
                            Color(hex: selectedCategory == category.category ? "3bb9f1" : "eeeeee"),
                            width: 0.5
                        )
                        .cornerRadius(16.7)
                        .overlay(
                            RoundedRectangle(cornerRadius: CGFloat(16.7))
                                .stroke(lineWidth: 0.5)
                                .foregroundColor(Color(hex: selectedCategory == category.category ? "3bb9f1" : "eeeeee"))
                        )
                        .onTapGesture {
                            if selectedCategory != category.category {
                                selectedCategory = category.category
                                selectCategory(category.categoryId)
                            }
                        }
                }
            }
        }
    }
}

#Preview {
    
    ContentListCategoryView(
        categoryList: [
            GetCategoryListResponse(categoryId: 0, category: "전체"),
            GetCategoryListResponse(categoryId: 1, category: "test"),
            GetCategoryListResponse(categoryId: 0, category: "test2")
        ],
        selectCategory: { _ in },
        selectedCategory: .constant("전체")
    )
}
