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.
189 lines
8.7 KiB
189 lines
8.7 KiB
//
|
|
// EventTournamentsView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 17/05/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
import PadelClubData
|
|
|
|
struct EventTournamentsView: View {
|
|
@EnvironmentObject var dataStore: DataStore
|
|
@Environment(NavigationViewModel.self) private var navigation
|
|
let event: Event
|
|
@State private var newTournament: Tournament?
|
|
@State private var mainTournament: Tournament?
|
|
@State private var showTournamentPicker: Bool = false
|
|
|
|
var presentTournamentCreationView: Binding<Bool> { Binding(
|
|
get: { newTournament != nil },
|
|
set: { isPresented in
|
|
if isPresented == false {
|
|
newTournament = nil
|
|
}
|
|
}
|
|
)}
|
|
|
|
var body: some View {
|
|
let tournaments = event.tournaments
|
|
List {
|
|
ForEach(tournaments) { tournament in
|
|
Section {
|
|
NavigationLink {
|
|
TournamentStatusView(tournament: tournament, eventDismiss: true)
|
|
} label: {
|
|
TournamentCellView(tournament: tournament)
|
|
.contextMenu {
|
|
|
|
NavigationLink {
|
|
TournamentSettingsView()
|
|
.environment(tournament)
|
|
} label: {
|
|
Label("Paramètres", systemImage: "gearshape.fill")
|
|
}
|
|
|
|
Button {
|
|
navigation.openTournamentInOrganizer(tournament)
|
|
} label: {
|
|
Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow")
|
|
}
|
|
}
|
|
}
|
|
} footer: {
|
|
if event.tournaments.count > 1 {
|
|
if let mainTournament, mainTournament == tournament {
|
|
Menu {
|
|
Button("Formats") {
|
|
tournaments.forEach { tournament in
|
|
tournament.groupStageMatchFormat = mainTournament.groupStageMatchFormat
|
|
tournament.loserBracketMatchFormat = mainTournament.loserBracketMatchFormat
|
|
tournament.matchFormat = mainTournament.matchFormat
|
|
}
|
|
dataStore.tournaments.addOrUpdate(contentOfs: tournaments)
|
|
}
|
|
|
|
Button("Infos JAP") {
|
|
tournaments.forEach { tournament in
|
|
tournament.setupUmpireSettings(defaultTournament: mainTournament)
|
|
}
|
|
dataStore.tournaments.addOrUpdate(contentOfs: tournaments)
|
|
}
|
|
|
|
Button("Réglages Inscriptions") {
|
|
tournaments.forEach { tournament in
|
|
tournament.setupRegistrationSettings(templateTournament: mainTournament)
|
|
}
|
|
dataStore.tournaments.addOrUpdate(contentOfs: tournaments)
|
|
}
|
|
} label: {
|
|
Text("Copier des réglages sur les autres tournois")
|
|
.underline()
|
|
.multilineTextAlignment(.leading)
|
|
}
|
|
|
|
} else {
|
|
Menu {
|
|
if tournament != self.mainTournament {
|
|
Button("Définir comme tournoi principal") {
|
|
self.mainTournament = tournament
|
|
}
|
|
}
|
|
|
|
if let mainTournament {
|
|
|
|
Divider()
|
|
|
|
Button("Copier les formats du tournoi principal") {
|
|
tournament.groupStageMatchFormat = mainTournament.groupStageMatchFormat
|
|
tournament.loserBracketMatchFormat = mainTournament.loserBracketMatchFormat
|
|
tournament.matchFormat = mainTournament.matchFormat
|
|
dataStore.tournaments.addOrUpdate(instance: tournament)
|
|
}
|
|
|
|
Button("Copier les infos JAP du tournoi principal") {
|
|
tournament.setupUmpireSettings(defaultTournament: mainTournament)
|
|
dataStore.tournaments.addOrUpdate(instance: tournament)
|
|
}
|
|
|
|
Button("Copier les réglages des inscriptions du tournoi principal") {
|
|
tournament.setupRegistrationSettings(templateTournament: mainTournament)
|
|
dataStore.tournaments.addOrUpdate(instance: tournament)
|
|
}
|
|
}
|
|
} label: {
|
|
Text("Options rapides pour certains réglages")
|
|
.underline()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
BarButtonView("Importer un tournoi", icon: "square.and.arrow.down") {
|
|
showTournamentPicker = true
|
|
}
|
|
}
|
|
if #available(iOS 26.0, *) {
|
|
ToolbarSpacer(placement: .topBarTrailing)
|
|
}
|
|
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
if #available(iOS 26.0, *) {
|
|
BarButtonView("Ajouter une indisponibilité", icon: "plus") {
|
|
let tournament = Tournament.newEmptyInstance()
|
|
newTournament = tournament
|
|
}
|
|
} else {
|
|
BarButtonView("Ajouter une indisponibilité", icon: "plus.circle.fill") {
|
|
let tournament = Tournament.newEmptyInstance()
|
|
newTournament = tournament
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.headerProminence(.increased)
|
|
.sheet(isPresented: $showTournamentPicker, content: {
|
|
NavigationStack {
|
|
TournamentPickerView(event: event)
|
|
.environmentObject(dataStore)
|
|
}
|
|
})
|
|
.sheet(isPresented: presentTournamentCreationView) {
|
|
if let newTournament {
|
|
NavigationStack {
|
|
List {
|
|
Section {
|
|
TournamentConfigurationView(tournament: newTournament)
|
|
}
|
|
Section {
|
|
RowButtonView("Ajouter le tournoi") {
|
|
newTournament.event = event.id
|
|
newTournament.courtCount = event.eventCourtCount()
|
|
newTournament.startDate = event.eventStartDate()
|
|
newTournament.dayDuration = event.eventDayDuration()
|
|
newTournament.initSettings(templateTournament: Tournament.getTemplateTournament(), overrideTeamCount: false)
|
|
dataStore.tournaments.addOrUpdate(instance: newTournament)
|
|
|
|
self.newTournament = nil
|
|
}
|
|
}
|
|
}
|
|
.toolbarBackground(.visible, for: .navigationBar)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.navigationTitle("Nouveau tournoi")
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Annuler", role: .cancel) {
|
|
self.newTournament = nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|