|
|
|
|
@ -8,6 +8,13 @@ |
|
|
|
|
import SwiftUI |
|
|
|
|
import PadelClubData |
|
|
|
|
|
|
|
|
|
public enum TeamPickType: String { |
|
|
|
|
case bracket = "bracket" |
|
|
|
|
case groupStage = "groupStage" |
|
|
|
|
case loserBracket = "loserBracket" |
|
|
|
|
case wildcard = "wildcard" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct TeamPickerView: View { |
|
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
|
@ -20,7 +27,7 @@ struct TeamPickerView: View { |
|
|
|
|
var shouldConfirm: Bool = false |
|
|
|
|
var groupStagePosition: Int? = nil |
|
|
|
|
var round: Round? = nil |
|
|
|
|
var matchTypeContext: MatchType = .bracket |
|
|
|
|
var pickTypeContext: TeamPickType = .bracket |
|
|
|
|
var luckyLosers: [TeamRegistration] = [] |
|
|
|
|
let teamPicked: ((TeamRegistration) -> (Void)) |
|
|
|
|
|
|
|
|
|
@ -31,21 +38,34 @@ struct TeamPickerView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var wording: String { |
|
|
|
|
switch pickTypeContext { |
|
|
|
|
case .bracket: |
|
|
|
|
return "Choisir" |
|
|
|
|
case .groupStage: |
|
|
|
|
return "Choisir" |
|
|
|
|
case .loserBracket: |
|
|
|
|
return "Choisir" |
|
|
|
|
case .wildcard: |
|
|
|
|
return "Choisir la wildcard" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
ConfirmButtonView(shouldConfirm: shouldConfirm, message: MatchSetupView.confirmationMessage) { |
|
|
|
|
presentTeamPickerView = true |
|
|
|
|
} label: { |
|
|
|
|
Text("Choisir") |
|
|
|
|
Text(wording) |
|
|
|
|
.underline() |
|
|
|
|
} |
|
|
|
|
.sheet(isPresented: $presentTeamPickerView) { |
|
|
|
|
NavigationStack { |
|
|
|
|
List { |
|
|
|
|
if matchTypeContext == .loserBracket, let losers = round?.parentRound?.losers() { |
|
|
|
|
if pickTypeContext == .loserBracket, let losers = round?.parentRound?.losers() { |
|
|
|
|
_sectionView(losers.sorted(by: \.weight, order: sortOrder), title: "Perdant du tour précédent") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if matchTypeContext == .loserBracket, let losers = round?.previousRound()?.winners() { |
|
|
|
|
if pickTypeContext == .loserBracket, let losers = round?.previousRound()?.winners() { |
|
|
|
|
_sectionView(losers.sorted(by: \.weight, order: sortOrder), title: "Gagnant du tour précédent") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -63,7 +83,11 @@ struct TeamPickerView: View { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let teams = tournament.selectedSortedTeams() |
|
|
|
|
if matchTypeContext == .loserBracket { |
|
|
|
|
if pickTypeContext == .wildcard { |
|
|
|
|
_sectionView(tournament.waitingListSortedTeams(selectedSortedTeams: teams).sorted(by: \.weight, order: sortOrder), title: "Liste d'attente") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if pickTypeContext == .loserBracket { |
|
|
|
|
_sectionView(teams.filter({ $0.inGroupStage() && $0.qualified == false }).sorted(by: \.weight, order: sortOrder), title: "Non qualifié de poules") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -145,7 +169,7 @@ struct TeamPickerView: View { |
|
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
|
.buttonStyle(.plain) |
|
|
|
|
.id(team.id) |
|
|
|
|
.listRowView(isActive: matchTypeContext == .loserBracket && round?.teams().map({ $0.id }).contains(team.id) == true, color: .green, hideColorVariation: true) |
|
|
|
|
.listRowView(isActive: pickTypeContext == .loserBracket && round?.teams().map({ $0.id }).contains(team.id) == true, color: .green, hideColorVariation: true) |
|
|
|
|
// .confirmationDialog("Attention", isPresented: confirmationRequest, titleVisibility: .visible) { |
|
|
|
|
// Button("Retirer du tableau", role: .destructive) { |
|
|
|
|
// teamPicked(confirmTeam!) |
|
|
|
|
|