//
//  TournamentConfiguratorView.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 22/03/2024.
//

import SwiftUI

struct TournamentConfigurationView: View {
    @Bindable var tournament: Tournament

    var minimumTeamsCount: Int {
        4
    }
    
    var maximumTeamsCount: Int {
        128
    }
    
    @ViewBuilder
    var body: some View {
        Picker(selection: $tournament.federalLevelCategory, label: Text("Niveau")) {
            ForEach(TournamentLevel.allCases) { type in
                Text(type.localizedLabel(.title)).tag(type)
            }
        }
        .onChange(of: tournament.federalLevelCategory) {
            if tournament.federalLevelCategory == .unlisted {
                tournament.federalCategory = .unlisted
                tournament.federalAgeCategory = .unlisted
            }
        }
        Picker(selection: $tournament.federalCategory, label: Text("Catégorie")) {
            ForEach(TournamentCategory.allCases) { type in
                Text(type.localizedLabel(.title)).tag(type)
            }
        }
        Picker(selection: $tournament.federalAgeCategory, label: Text("Limite d'âge")) {
            ForEach(FederalTournamentAge.allCases) { type in
                Text(type.localizedLabel(.title)).tag(type)
            }
        }
        LabeledContent {
            StepperView(count: $tournament.teamCount, minimum: minimumTeamsCount, maximum: maximumTeamsCount)
        } label: {
            Text("Équipes souhaitées")
        }
    }
}
//
//#Preview {
//    TournamentConfiguratorView()
//}
