//
//  RegionsStep.swift
//  SportsTime
//
//  Step 4 of the trip wizard - select geographic regions.
//

import SwiftUI

struct RegionsStep: View {
    @Environment(\.colorScheme) private var colorScheme
    @Binding var selectedRegions: Set<Region>

    var body: some View {
        VStack(alignment: .leading, spacing: Theme.Spacing.md) {
            StepHeader(
                title: "Where do you want to go?",
                subtitle: "Tap the map to select regions"
            )

            RegionMapSelector(
                selectedRegions: $selectedRegions,
                onToggle: { region in
                    toggleRegion(region)
                }
            )
        }
        .padding(Theme.Spacing.lg)
        .background(Theme.cardBackground(colorScheme))
        .clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.large))
        .overlay {
            RoundedRectangle(cornerRadius: Theme.CornerRadius.large)
                .stroke(Theme.surfaceGlow(colorScheme), lineWidth: 1)
        }
    }

    private func toggleRegion(_ region: Region) {
        if selectedRegions.contains(region) {
            selectedRegions.remove(region)
        } else {
            selectedRegions.insert(region)
        }
    }
}

// MARK: - Preview

#Preview {
    RegionsStep(selectedRegions: .constant([.east, .central]))
        .padding()
        .themedBackground()
}
