// // TeamsCallingView.swift // PadelClub // // Created by razmig on 10/07/2024. // import SwiftUI import LeStorage struct TeamsCallingView: View { @Environment(Tournament.self) var tournament: Tournament let teams : [TeamRegistration] var body: some View { List { PlayersWithoutContactView(players: teams.flatMap({ $0.unsortedPlayers() }).sorted(by: \.computedRank)) let called = teams.filter { tournament.isStartDateIsDifferentThanCallDate($0) == false } let justCalled = teams.filter { $0.called() } let label = "\(justCalled.count.formatted()) / \(teams.count.formatted()) convoquées (dont \(called.count.formatted()) au bon horaire)" Text(label) Section { ForEach(teams) { team in Menu { _menuOptions(team: team) } label: { HStack { TeamRowView(team: team, displayCallDate: true) Spacer() Menu { _menuOptions(team: team) } label: { LabelOptions().labelStyle(.iconOnly) } } } .buttonStyle(.plain) .listRowView(isActive: team.confirmed(), color: .green, hideColorVariation: true) } } footer: { HStack { Text("Vous pouvez indiquer si une équipe vous a confirmé sa convocation en appuyant sur ") Image(systemName: "ellipsis.circle").font(.footnote) } } } .headerProminence(.increased) .navigationTitle("Statut des équipes") .navigationBarTitleDisplayMode(.inline) .toolbarBackground(.visible, for: .navigationBar) } @ViewBuilder func _menuOptions(team: TeamRegistration) -> some View { Button { team.toggleSummonConfirmation() do { try self.tournament.tournamentStore.teamRegistrations.addOrUpdate(instance: team) } catch { Logger.error(error) } } label: { if team.confirmed() { Label("Confirmation reçue", systemImage: "checkmark.circle.fill").foregroundStyle(.green) } else { Label("Confirmation reçue", systemImage: "circle").foregroundStyle(.logoRed) } } Divider() Button(role: .destructive) { team.callDate = nil do { try self.tournament.tournamentStore.teamRegistrations.addOrUpdate(instance: team) } catch { Logger.error(error) } } label: { Text("Effacer la date de convocation") } Divider() Button(role: .destructive) { team.callDate = team.initialMatch()?.startDate ?? tournament.startDate do { try self.tournament.tournamentStore.teamRegistrations.addOrUpdate(instance: team) } catch { Logger.error(error) } } label: { Text("Indiquer comme convoquée") } } }