diff --git a/PadelClub/Views/Planning/PlanningByCourtView.swift b/PadelClub/Views/Planning/PlanningByCourtView.swift index bf8d7a4..9b0744a 100644 --- a/PadelClub/Views/Planning/PlanningByCourtView.swift +++ b/PadelClub/Views/Planning/PlanningByCourtView.swift @@ -43,13 +43,16 @@ struct PlanningByCourtView: View { _selectedDay = State(wrappedValue: startDate) } + @ViewBuilder var body: some View { + let noStartDate = matches.allSatisfy({ $0.startDate == nil }) + List { - _byCourtView() + _byCourtView(noStartDate: noStartDate) .id(selectedCourt) } .overlay { - if matches.allSatisfy({ $0.startDate == nil }) { + if noStartDate { ContentUnavailableView { Label("Aucun horaire défini", systemImage: "clock.badge.questionmark") } description: { @@ -59,13 +62,6 @@ struct PlanningByCourtView: View { selectedScheduleDestination = nil } } - } else if courtSlots.isEmpty == false { - ContentUnavailableView { - Label("Aucun match plannifié", systemImage: "clock.badge.questionmark") - } description: { - Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné") - } actions: { - } } } .navigationTitle(Text(selectedDay.formatted(.dateTime.day().weekday().month()))) @@ -87,7 +83,7 @@ struct PlanningByCourtView: View { Picker(selection: $selectedCourt) { ForEach(courts, id: \.self) { courtIndex in if courtIndex == Int.max { - Image(systemName: "rectangle.slash").tag(Int.max) + Label("Sans terrain", systemImage: "rectangle.slash").tag(Int.max) } else { Text(tournament.courtName(atIndex: courtIndex)).tag(courtIndex) } @@ -102,29 +98,45 @@ struct PlanningByCourtView: View { } @ViewBuilder - func _byCourtView() -> some View { + func _byCourtView(noStartDate: Bool) -> some View { if let _matches = courtSlots[selectedCourt]?.filter({ $0.startDate?.dayInt == selectedDay.dayInt }) { let _sortedMatches = _matches.sorted(by: \.computedStartDateForSorting) - ForEach(_sortedMatches.indices, id: \.self) { index in - let match = _sortedMatches[index] - Section { - MatchRowView(match: match, matchViewStyle: .feedStyle) - } header: { - if let startDate = match.startDate { - if index > 0 { - if match.confirmed { - Text("Pas avant \(startDate.formatted(date: .omitted, time: .shortened))") + if _sortedMatches.isEmpty == false { + ForEach(_sortedMatches.indices, id: \.self) { index in + let match = _sortedMatches[index] + Section { + MatchRowView(match: match, matchViewStyle: .feedStyle) + } header: { + if let startDate = match.startDate { + if index > 0 { + if match.confirmed { + Text("Pas avant \(startDate.formatted(date: .omitted, time: .shortened))") + } else { + Text("Suivi de") + } } else { - Text("Suivi de") + Text("Démarrage à \(startDate.formatted(date: .omitted, time: .shortened))") } } else { - Text("Démarrage à \(startDate.formatted(date: .omitted, time: .shortened))") + Text("Aucun horaire") } - } else { - Text("Aucun horaire") } + .headerProminence(.increased) } - .headerProminence(.increased) + } else if noStartDate == false { + ContentUnavailableView { + Label("Aucun match plannifié", systemImage: "clock.badge.questionmark") + } description: { + Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné") + } actions: { + } + } + } else if noStartDate == false { + ContentUnavailableView { + Label("Aucun match plannifié", systemImage: "clock.badge.questionmark") + } description: { + Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné") + } actions: { } } } diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index 4d3e783..ad7b39b 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -48,6 +48,11 @@ struct TableStructureView: View { var maxGroupStages: Int { teamCount / max(1, teamsPerGroupStage) } + + var tsPure: Int { + max(teamCount - groupStageCount * teamsPerGroupStage, 0) + } + @ViewBuilder var body: some View { @@ -191,12 +196,14 @@ struct TableStructureView: View { } if structurePreset == .manual { - LabeledContent { - let tsPure = max(teamCount - groupStageCount * teamsPerGroupStage, 0) Text(tsPure.formatted()) } label: { Text("Nombre de têtes de série") + + if tsPure > 0 && (tsPure > teamCount / 2 || tsPure < teamCount / 8 || tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified) { + Text("Attention !").foregroundStyle(.red) + } } LabeledContent { Text(tf.formatted()) @@ -212,6 +219,16 @@ struct TableStructureView: View { Text("Total de matchs") } } + } footer: { + if tsPure > 0 && structurePreset == .manual { + if tsPure > teamCount / 2 { + Text("Le nombre de têtes de série ne devrait pas être supérieur à la moitié de l'effectif").foregroundStyle(.red) + } else if tsPure < teamCount / 8 { + Text("À partir du moment où vous avez des têtes de série, leur nombre ne devrait pas être inférieur à 1/8ème de l'effectif").foregroundStyle(.red) + } else if tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified { + Text("Le nombre de têtes de série ne devrait pas être inférieur au nombre de paires qualifiées sortantes").foregroundStyle(.red) + } + } }