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.
127 lines
4.2 KiB
127 lines
4.2 KiB
//
|
|
// TournamentCallView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 16/04/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
enum CallDestination: Identifiable, Selectable, Equatable {
|
|
|
|
static func == (lhs: CallDestination, rhs: CallDestination) -> Bool {
|
|
return lhs.id == rhs.id
|
|
}
|
|
|
|
case teams(Tournament)
|
|
case seeds(Tournament)
|
|
case groupStages(Tournament)
|
|
|
|
var id: String {
|
|
switch self {
|
|
case .teams:
|
|
return "teams"
|
|
case .seeds:
|
|
return "seed"
|
|
case .groupStages:
|
|
return "groupStage"
|
|
}
|
|
}
|
|
|
|
func selectionLabel(index: Int) -> String {
|
|
switch self {
|
|
case .teams:
|
|
return "Statut"
|
|
case .seeds:
|
|
return "Têtes de série"
|
|
case .groupStages:
|
|
return "Poules"
|
|
}
|
|
}
|
|
|
|
func badgeValue() -> Int? {
|
|
switch self {
|
|
case .teams(let tournament):
|
|
let allSeedCalled = tournament.selectedSortedTeams().filter({ tournament.isStartDateIsDifferentThanCallDate($0) || $0.callDate == nil })
|
|
return allSeedCalled.count
|
|
case .seeds(let tournament):
|
|
let allSeedCalled = tournament.seeds().filter({ tournament.isStartDateIsDifferentThanCallDate($0) || $0.callDate == nil })
|
|
return allSeedCalled.count
|
|
case .groupStages(let tournament):
|
|
let allSeedCalled = tournament.groupStageTeams().filter({ tournament.isStartDateIsDifferentThanCallDate($0) || $0.callDate == nil })
|
|
return allSeedCalled.count
|
|
}
|
|
}
|
|
|
|
func badgeValueColor() -> Color? {
|
|
return nil
|
|
}
|
|
|
|
func badgeImage() -> Badge? {
|
|
switch self {
|
|
case .teams(let tournament):
|
|
let allSeedCalled = tournament.selectedSortedTeams().allSatisfy({ tournament.isStartDateIsDifferentThanCallDate($0) == false })
|
|
return allSeedCalled ? .checkmark : nil
|
|
case .seeds(let tournament):
|
|
let allSeedCalled = tournament.seeds().allSatisfy({ tournament.isStartDateIsDifferentThanCallDate($0) == false })
|
|
return allSeedCalled ? .checkmark : nil
|
|
case .groupStages(let tournament):
|
|
let allSeedCalled = tournament.groupStageTeams().allSatisfy({ tournament.isStartDateIsDifferentThanCallDate($0) == false })
|
|
return allSeedCalled ? .checkmark : nil
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
struct TournamentCallView: View {
|
|
var tournament: Tournament
|
|
@State private var selectedDestination: CallDestination?
|
|
let allDestinations: [CallDestination]
|
|
|
|
init(tournament: Tournament) {
|
|
self.tournament = tournament
|
|
var destinations = [CallDestination]()
|
|
let groupStageTeams = tournament.groupStageTeams()
|
|
if groupStageTeams.isEmpty == false {
|
|
destinations.append(.groupStages(tournament))
|
|
self._selectedDestination = State(wrappedValue: .groupStages(tournament))
|
|
}
|
|
if tournament.seededTeams().isEmpty == false {
|
|
destinations.append(.seeds(tournament))
|
|
if groupStageTeams.isEmpty {
|
|
self._selectedDestination = State(wrappedValue: .seeds(tournament))
|
|
}
|
|
}
|
|
destinations.append(.teams(tournament))
|
|
self.allDestinations = destinations
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
GenericDestinationPickerView(selectedDestination: $selectedDestination, destinations: allDestinations, nilDestinationIsValid: true)
|
|
switch selectedDestination {
|
|
case .none:
|
|
CallSettingsView()
|
|
case .some(let selectedCall):
|
|
switch selectedCall {
|
|
case .teams:
|
|
TeamsCallingView(teams: tournament.selectedSortedTeams())
|
|
case .groupStages:
|
|
GroupStageCallingView()
|
|
case .seeds:
|
|
SeedsCallingView()
|
|
}
|
|
}
|
|
}
|
|
.environment(tournament)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbarBackground(.visible, for: .navigationBar)
|
|
.navigationTitle("Convocations")
|
|
}
|
|
|
|
}
|
|
|
|
//#Preview {
|
|
// TournamentCallView(tournament: Tournament.mock())
|
|
//}
|
|
|