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.
93 lines
3.1 KiB
93 lines
3.1 KiB
//
|
|
// SendToAllView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 28/04/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
|
|
struct SendToAllView: View {
|
|
@Environment(Tournament.self) var tournament: Tournament
|
|
@State private var contactMethod: Int = 1
|
|
@State private var contactRecipients: Set<String> = Set()
|
|
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
List(selection: $contactRecipients) {
|
|
Section {
|
|
Picker(selection: $contactMethod) {
|
|
Text("Contacter par sms").tag(0)
|
|
Text("Contacter par mail").tag(1)
|
|
} label: {
|
|
Text("méthode")
|
|
}
|
|
.labelsHidden()
|
|
.pickerStyle(.inline)
|
|
}
|
|
|
|
Section {
|
|
ForEach(tournament.groupStages()) { groupStage in
|
|
let teams = groupStage.teams()
|
|
if teams.isEmpty == false {
|
|
LabeledContent {
|
|
Text(teams.count.formatted() + " équipe" + teams.count.pluralSuffix)
|
|
} label: {
|
|
Text(groupStage.groupStageTitle())
|
|
}
|
|
.tag(groupStage.id)
|
|
}
|
|
|
|
}
|
|
ForEach(tournament.rounds()) { round in
|
|
let teams = round.teams()
|
|
if teams.isEmpty == false {
|
|
LabeledContent {
|
|
Text(teams.count.formatted() + " équipe" + teams.count.pluralSuffix)
|
|
} label: {
|
|
Text(round.roundTitle())
|
|
}
|
|
.tag(round.id)
|
|
}
|
|
}
|
|
}
|
|
|
|
Section {
|
|
RowButtonView("Contacter \(_totalString())") {
|
|
|
|
}
|
|
}
|
|
}
|
|
.environment(\.editMode, Binding.constant(EditMode.active))
|
|
.headerProminence(.increased)
|
|
.navigationTitle("Réglages")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbarBackground(.visible, for: .navigationBar)
|
|
}
|
|
}
|
|
|
|
func _teams() -> [TeamRegistration] {
|
|
let rounds : [Round] = contactRecipients.compactMap { Store.main.findById($0) }
|
|
return rounds.flatMap({ $0.teams() })
|
|
}
|
|
|
|
func _groupStagesTeams() -> [TeamRegistration] {
|
|
let groupStages : [GroupStage] = contactRecipients.compactMap { Store.main.findById($0) }
|
|
return groupStages.flatMap({ $0.teams() })
|
|
}
|
|
|
|
func _totalString() -> String {
|
|
if contactRecipients.isEmpty {
|
|
return "toutes les équipes"
|
|
} else {
|
|
let teams = _teams() + _groupStagesTeams()
|
|
return teams.count.formatted() + " équipe" + teams.count.pluralSuffix
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
SendToAllView()
|
|
}
|
|
|