@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct GroupStagesView : View {
var tournament : Tournament
@ -16,7 +17,7 @@ struct GroupStagesView: View {
lhs . id = = rhs . id
}
case all
case all ( Tournament )
case groupStage ( GroupStage )
var id : String {
@ -52,8 +53,12 @@ struct GroupStagesView: View {
func badgeImage ( ) -> Badge ? {
switch self {
case . all :
return nil
case . all ( let tournament ) :
if tournament . groupStageAdditionalQualified > 0 && tournament . moreQualifiedToDraw ( ) > 0 && tournament . missingQualifiedFromGroupStages ( ) . isEmpty = = false {
return . custom ( systemName : " exclamationmark.circle.fill " , color : . logoBackground )
} else {
return nil
}
case . groupStage ( let groupStage ) :
return groupStage . badgeImage ( )
}
@ -80,7 +85,7 @@ struct GroupStagesView: View {
}
func allDestinations ( ) -> [ GroupStageDestination ] {
var allDestinations : [ GroupStageDestination ] = [ . all ]
var allDestinations : [ GroupStageDestination ] = [ . all ( tournament ) ]
let groupStageDestinations : [ GroupStageDestination ] = tournament . groupStages ( ) . map { GroupStageDestination . groupStage ( $0 ) }
allDestinations . append ( contentsOf : groupStageDestinations )
return allDestinations
@ -94,6 +99,40 @@ struct GroupStagesView: View {
let finishedMatches = tournament . finishedMatches ( allMatches )
List {
if tournament . groupStageAdditionalQualified > 0 {
let missingQualifiedFromGroupStages = tournament . missingQualifiedFromGroupStages ( )
Section {
let name = " \( ( tournament . qualifiedPerGroupStage + 1 ) . ordinalFormatted ( ) ) "
NavigationLink {
SpinDrawView ( drawees : [ " Qualification d'un \( name ) de poule " ] , segments : missingQualifiedFromGroupStages ) { results in
results . forEach { drawResult in
missingQualifiedFromGroupStages [ drawResult . drawIndex ] . qualified = true
do {
try self . tournament . tournamentStore . teamRegistrations . addOrUpdate ( instance : missingQualifiedFromGroupStages [ drawResult . drawIndex ] )
} catch {
Logger . error ( error )
}
}
}
} label : {
Label {
Text ( " Qualifier un \( name ) de poule par tirage au sort " )
} icon : {
Image ( systemName : " exclamationmark.circle.fill " )
. foregroundStyle ( . logoBackground )
}
}
. disabled ( tournament . moreQualifiedToDraw ( ) = = 0 || missingQualifiedFromGroupStages . isEmpty )
} footer : {
if tournament . moreQualifiedToDraw ( ) = = 0 {
Text ( " Aucune équipe supplémentaire à qualifier. Vous pouvez en rajouter en modifier le paramètre dans structure. " )
} else if missingQualifiedFromGroupStages . isEmpty {
Text ( " Aucune équipe supplémentaire à tirer au sort. Attendez la fin des poules. " )
}
}
}
let runningMatches = tournament . runningMatches ( allMatches )
MatchListView ( section : " en cours " , matches : runningMatches , matchViewStyle : . standardStyle , isExpanded : false )
MatchListView ( section : " prêt à démarrer " , matches : tournament . availableToStart ( allMatches , in : runningMatches ) , matchViewStyle : . standardStyle , isExpanded : false )