//
//  TournamentLevelPickerView.swift
//  Padel Tournament
//
//  Created by Razmig Sarkissian on 05/10/2023.
//

import SwiftUI

struct TournamentLevelPickerView: View {
    @Environment(Tournament.self) private var tournament: Tournament

    var body: some View {
        @Bindable var tournament = tournament

        Picker(selection: $tournament.tournamentLevel, 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.tournamentCategory, label: Text("Catégorie")) {
            ForEach(TournamentCategory.allCases) { type in
                Text(type.localizedLabel(.title)).tag(type)
            }
        }

        Picker(selection: $tournament.federalTournamentAge, label: Text("Limite d'âge")) {
            ForEach(FederalTournamentAge.allCases) { type in
                Text(type.localizedLabel(.title)).tag(type)
            }
        }
        Picker(selection: $tournament.groupStageOrderingMode, label: Text("Répartition en poule")) {
            ForEach(GroupStageOrderingMode.allCases) { type in
                Text(type.localizedLabel()).tag(type)
            }
        }
    }
}
