|
|
|
|
@ -16,6 +16,7 @@ struct ConsolationTournamentImportView: View { |
|
|
|
|
@State private var selectedTournament: Tournament? |
|
|
|
|
@State private var selectedImportSelector: ImportSelector = .groupStage |
|
|
|
|
@State private var selectedImportType: ImportType = .losers |
|
|
|
|
@State private var selectedGroupStagePosition: Set<Int> = Set() |
|
|
|
|
|
|
|
|
|
enum ImportType: Int, Identifiable, CaseIterable { |
|
|
|
|
case losers |
|
|
|
|
@ -134,6 +135,36 @@ struct ConsolationTournamentImportView: View { |
|
|
|
|
Text("Type") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if selectedImportSelector == .groupStage, selectedImportType == .losers { |
|
|
|
|
NavigationLink { |
|
|
|
|
List(selection: $selectedGroupStagePosition) { |
|
|
|
|
ForEach(selectedTournament.groupStageLosingPositions()) { position in |
|
|
|
|
let text: String = "\(position)" + position.ordinalFormattedSuffix() |
|
|
|
|
Text(text) |
|
|
|
|
.tag(position) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.environment(\.editMode, Binding.constant(EditMode.active)) |
|
|
|
|
.navigationTitle("Position des poules") |
|
|
|
|
.navigationBarTitleDisplayMode(.inline) |
|
|
|
|
.toolbarBackground(.visible, for: .navigationBar) |
|
|
|
|
} label: { |
|
|
|
|
LabeledContent { |
|
|
|
|
if selectedGroupStagePosition.isEmpty { |
|
|
|
|
Text("Tous les perdants") |
|
|
|
|
} else { |
|
|
|
|
let value: String = selectedGroupStagePosition.map({ position in |
|
|
|
|
let text: String = "\(position)" + position.ordinalFormattedSuffix() |
|
|
|
|
return text |
|
|
|
|
}).joined(separator: ", ") |
|
|
|
|
Text(value) |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
Text("Sélection des positions") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -154,16 +185,15 @@ struct ConsolationTournamentImportView: View { |
|
|
|
|
|
|
|
|
|
let teams = _teamsToImport(selectedTournament: selectedTournament) |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
RowButtonView("Importer les équipes") { |
|
|
|
|
await _importTeams(selectedTournament: selectedTournament, teams: teams) |
|
|
|
|
dismiss() |
|
|
|
|
} |
|
|
|
|
.disabled(teams.isEmpty) |
|
|
|
|
} footer: { |
|
|
|
|
if teams.isEmpty { |
|
|
|
|
Text("Aucune équipe détectée").foregroundStyle(.logoRed) |
|
|
|
|
if teams.isEmpty == false { |
|
|
|
|
Section { |
|
|
|
|
RowButtonView("Importer les \(teams.count) équipes") { |
|
|
|
|
await _importTeams(selectedTournament: selectedTournament, teams: teams) |
|
|
|
|
dismiss() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
Text("Aucune équipe à importer").foregroundStyle(.logoRed) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -185,7 +215,13 @@ struct ConsolationTournamentImportView: View { |
|
|
|
|
teams = selectedTournament.groupStageTeams().filter({ |
|
|
|
|
switch selectedImportType { |
|
|
|
|
case .losers: |
|
|
|
|
return $0.qualified == false |
|
|
|
|
if selectedGroupStagePosition.isEmpty { |
|
|
|
|
return $0.qualified == false |
|
|
|
|
} else if let position = $0.groupStagePosition { |
|
|
|
|
return $0.qualified == false && selectedGroupStagePosition.contains(position) |
|
|
|
|
} else { |
|
|
|
|
return $0.qualified == false |
|
|
|
|
} |
|
|
|
|
case .winners: |
|
|
|
|
return $0.qualified |
|
|
|
|
case .all: |
|
|
|
|
|