import SwiftUI

struct FilterBar: View {
    let currentFilter: TodoFilter
    let countForFilter: (TodoFilter) -> Int
    let onFilterSelected: (TodoFilter) -> Void

    var body: some View {
        HStack(spacing: 8) {
            ForEach(TodoFilter.allCases) { filter in
                let isSelected = currentFilter == filter
                let count = countForFilter(filter)

                Button {
                    onFilterSelected(filter)
                } label: {
                    Text("\(filter.displayName) (\(count))")
                        .font(.subheadline)
                        .fontWeight(isSelected ? .semibold : .regular)
                        .padding(.horizontal, 14)
                        .padding(.vertical, 8)
                        .background(
                            Capsule()
                                .fill(isSelected ? Color.accentColor : Color(.systemGray5))
                        )
                        .foregroundStyle(isSelected ? .white : .primary)
                }
                .buttonStyle(.plain)
            }
            Spacer()
        }
        .padding(.horizontal, 16)
        .padding(.vertical, 8)
    }
}
