You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
8.0 KiB
205 lines
8.0 KiB
//
|
|
// TournamentBuildView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 19/05/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct TournamentBuildView: View {
|
|
var tournament: Tournament
|
|
@State private var bracketStatus: (status: String, description: String?, cut: TeamRegistration.TeamRange?)?
|
|
@State private var groupStageStatus: (String, TeamRegistration.TeamRange?)?
|
|
@State private var callStatus: Tournament.TournamentStatus?
|
|
@State private var scheduleStatus: Tournament.TournamentStatus?
|
|
@State private var cashierStatus: Tournament.TournamentStatus?
|
|
|
|
@ViewBuilder
|
|
var body: some View {
|
|
let state = tournament.state()
|
|
|
|
Section {
|
|
if tournament.groupStageCount > 0 {
|
|
NavigationLink(value: Screen.groupStage) {
|
|
LabeledContent {
|
|
if let groupStageStatus {
|
|
Text(groupStageStatus.0).lineLimit(1)
|
|
.multilineTextAlignment(.trailing)
|
|
} else {
|
|
ProgressView()
|
|
}
|
|
} label: {
|
|
Text("Poules")
|
|
if tournament.groupStagesAreOver(), tournament.moreQualifiedToDraw() > 0 {
|
|
let moreQualifiedToDraw = tournament.moreQualifiedToDraw()
|
|
Text("Qualifié\(moreQualifiedToDraw.pluralSuffix) sortant\(moreQualifiedToDraw.pluralSuffix) manquant\(moreQualifiedToDraw.pluralSuffix)").foregroundStyle(.logoRed)
|
|
} else if tournament.shouldVerifyGroupStage {
|
|
Text("Vérifier les poules").foregroundStyle(.logoRed)
|
|
} else if let range = groupStageStatus?.1 {
|
|
HStack {
|
|
if let left = range.left {
|
|
Text(left.weight.formatted())
|
|
}
|
|
|
|
if let right = range.right {
|
|
Image(systemName: "arrowshape.forward.fill")
|
|
Text(right.weight.formatted())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
groupStageStatus = await tournament.groupStageStatus()
|
|
}
|
|
}
|
|
|
|
if tournament.rounds().isEmpty == false {
|
|
NavigationLink(value: Screen.round) {
|
|
LabeledContent {
|
|
if let bracketStatus {
|
|
Text(bracketStatus.0).lineLimit(1)
|
|
.multilineTextAlignment(.trailing)
|
|
} else {
|
|
ProgressView()
|
|
}
|
|
} label: {
|
|
Text("Tableau")
|
|
if tournament.shouldVerifyBracket {
|
|
Text("Vérifier le tableau").foregroundStyle(.logoRed)
|
|
} else if let description = bracketStatus?.1 {
|
|
Text(description)
|
|
} else if let range = bracketStatus?.2 {
|
|
HStack {
|
|
if let left = range.left {
|
|
Text(left.weight.formatted())
|
|
}
|
|
|
|
if let right = range.right {
|
|
Image(systemName: "arrowshape.forward.fill")
|
|
Text(right.weight.formatted())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
bracketStatus = await tournament.bracketStatus()
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Section {
|
|
#if DEBUG
|
|
NavigationLink(value: Screen.rankings) {
|
|
LabeledContent {
|
|
if tournament.publishRankings == false {
|
|
Image(systemName: "exclamationmark.circle.fill")
|
|
.foregroundStyle(.logoYellow)
|
|
} else {
|
|
Image(systemName: "checkmark")
|
|
.foregroundStyle(.green)
|
|
}
|
|
} label: {
|
|
Text("Classement final des équipes")
|
|
if tournament.publishRankings == false {
|
|
Text("Vérifiez le classement avant de publier").foregroundStyle(.logoRed)
|
|
}
|
|
}
|
|
}
|
|
#else
|
|
if tournament.hasEnded() {
|
|
NavigationLink(value: Screen.rankings) {
|
|
LabeledContent {
|
|
if tournament.publishRankings == false {
|
|
Image(systemName: "exclamationmark.circle.fill")
|
|
.foregroundStyle(.logoYellow)
|
|
} else {
|
|
Image(systemName: "checkmark")
|
|
.foregroundStyle(.green)
|
|
}
|
|
} label: {
|
|
Text("Classement final des équipes")
|
|
if tournament.publishRankings == false {
|
|
Text("Vérifiez le classement avant de publier").foregroundStyle(.logoRed)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
if state == .running || state == .finished {
|
|
TournamentInscriptionView(tournament: tournament)
|
|
TournamentBroadcastRowView(tournament: tournament)
|
|
}
|
|
|
|
NavigationLink(value: Screen.schedule) {
|
|
let tournamentStatus = scheduleStatus
|
|
LabeledContent {
|
|
if let tournamentStatus {
|
|
Text(tournamentStatus.completion)
|
|
} else {
|
|
ProgressView()
|
|
}
|
|
} label: {
|
|
Text("Horaires et formats")
|
|
if let tournamentStatus {
|
|
Text(tournamentStatus.label).lineLimit(1)
|
|
} else {
|
|
Text(" ")
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
scheduleStatus = await tournament.scheduleStatus()
|
|
}
|
|
|
|
NavigationLink(value: Screen.call) {
|
|
let tournamentStatus = callStatus
|
|
LabeledContent {
|
|
if let tournamentStatus {
|
|
Text(tournamentStatus.completion)
|
|
} else {
|
|
ProgressView()
|
|
}
|
|
} label: {
|
|
Text("Convocations")
|
|
if let tournamentStatus {
|
|
Text(tournamentStatus.label).lineLimit(1)
|
|
} else {
|
|
Text(" ")
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
callStatus = await tournament.callStatus()
|
|
}
|
|
|
|
NavigationLink(value: Screen.cashier) {
|
|
let tournamentStatus = cashierStatus
|
|
LabeledContent {
|
|
if let tournamentStatus {
|
|
Text(tournamentStatus.completion)
|
|
} else {
|
|
ProgressView()
|
|
}
|
|
} label: {
|
|
Text("Encaissement")
|
|
if let tournamentStatus {
|
|
Text(tournamentStatus.label).lineLimit(1)
|
|
} else {
|
|
Text(" ")
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
cashierStatus = await tournament.cashierStatus()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//#Preview {
|
|
// TournamentBuildView(tournament: Tournament.mock())
|
|
//}
|
|
|