// // CallSettingsView.swift // PadelClub // // Created by Razmig Sarkissian on 16/04/2024. // import SwiftUI import LeStorage struct CallSettingsView: View { @EnvironmentObject var dataStore: DataStore @Environment(Tournament.self) var tournament: Tournament @State private var showSendToAllView: Bool = false @State private var addLink: Bool = false var tournamentStore: TournamentStore? { return self.tournament.tournamentStore } var body: some View { List { Section { NavigationLink { CallMessageCustomizationView(tournament: tournament) } label: { Text("Personnaliser le message de convocation") } } Section { RowButtonView("Envoyer un message à tout le monde") { showSendToAllView = true } } Section { RowButtonView("Envoyer le lien du tournoi") { addLink = true } .disabled(tournament.isPrivate) } footer: { if tournament.isPrivate { Button { tournament.isPrivate = false do { try dataStore.tournaments.addOrUpdate(instance: tournament) } catch { Logger.error(error) } } label: { Text(.init("Le tournoi est privée, le publier ?")).underline().foregroundStyle(.master) } } } // #if DEBUG Section { RowButtonView("Retirer toutes les convocations", role: .destructive) { let teams = tournament.unsortedTeams() teams.forEach { team in team.callDate = nil } do { try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams) } catch { Logger.error(error) } } } footer: { Text("Retire l'horaire de convocation enregistré pour toutes les équipes.") } Section { RowButtonView("Tout le monde a été convoqué", role: .destructive) { let teams = tournament.unsortedTeams() teams.forEach { team in if team.callDate == nil { team.callDate = team.expectedSummonDate() } } do { try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams) } catch { Logger.error(error) } } } footer: { Text("Pour toutes les équipes sans convocation, les indiquer comme ayant été convoquée.") } //#endif } .sheet(isPresented: $showSendToAllView) { SendToAllView(addLink: false) .tint(.master) } .sheet(isPresented: $addLink) { SendToAllView(addLink: true) .tint(.master) } } } //#Preview { // CallSettingsView() //}