import SwiftUI

struct SegmentedPickerSection<Selection: Hashable>: View {
    let title: String
    @Binding var selection: Selection
    let options: [(label: String, tag: Selection)]
    let accessibilityIdentifier: String

    var body: some View {
        HStack(spacing: 8) {
            ForEach(options, id: \.tag) { option in
                let isSelected = selection == option.tag
                Button {
                    withAnimation(.snappy(duration: 0.2)) {
                        selection = option.tag
                    }
                } label: {
                    Text(option.label)
                        .font(.subheadline)
                        .fontWeight(isSelected ? .semibold : .regular)
                        .padding(.horizontal, 14)
                        .padding(.vertical, 7)
                        .frame(maxWidth: .infinity)
                        .foregroundStyle(isSelected ? .primary : .secondary)
                        .glassEffect(.regular.tint(isSelected ? .blue : .clear), in: .capsule)
                }
                .buttonStyle(.plain)
            }
        }
        .padding(.horizontal)
        .padding(.vertical, 6)
        .accessibilityIdentifier(accessibilityIdentifier)
    }
}

struct LoadingListSection: View {
    var body: some View {
        Section {
            HStack {
                Spacer()
                ProgressView()
                Spacer()
            }
            .listRowBackground(Color.clear)
        }
    }
}
