//
//  ContentMainRankingSortView.swift
//  SodaLive
//
//  Created by klaus on 2023/11/03.
//

import SwiftUI

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

struct ContentMainRankingSortView_Previews: PreviewProvider {
    static var previews: some View {
        ContentMainRankingSortView(
            sorts: ["전체", "테마1", "테마2"],
            selectSort: { _ in },
            selectedSort: .constant("전체")
        )
    }
}
