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.
80 lines
2.2 KiB
80 lines
2.2 KiB
//
|
|
// MenuWarningView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by razmig on 28/04/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MenuWarningView: View {
|
|
let teams: [TeamRegistration]
|
|
var date: Date?
|
|
var message: String?
|
|
var umpireMail: String?
|
|
var subject: String?
|
|
|
|
@Binding var contactType: ContactType?
|
|
|
|
private func _getUmpireMail() -> [String]? {
|
|
if let umpireMail {
|
|
return [umpireMail]
|
|
}
|
|
return nil
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func _actionView(players: [PlayerRegistration], privateMode: Bool = false) -> some View {
|
|
Button("Message") {
|
|
contactType = .message(date: date, recipients: players.compactMap({ $0.phoneNumber }), body: message, tournamentBuild: nil)
|
|
}
|
|
Button("Mail") {
|
|
contactType = .mail(date: date, recipients: privateMode ? _getUmpireMail() : players.compactMap({ $0.email }), bccRecipients: privateMode ? players.compactMap({ $0.email }) : nil, body: message, subject: subject, tournamentBuild: nil)
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
|
|
Menu {
|
|
Menu("Tout le monde") {
|
|
let players = teams.flatMap({ $0.players() })
|
|
_actionView(players: players, privateMode: true)
|
|
}
|
|
Divider()
|
|
ForEach(teams) { team in
|
|
_teamView(team)
|
|
}
|
|
} label: {
|
|
Text("Prévenir")
|
|
.underline()
|
|
}
|
|
}
|
|
|
|
func _playerView(_ player: PlayerRegistration) -> some View {
|
|
Menu {
|
|
let players = [player]
|
|
_actionView(players: players)
|
|
} label: {
|
|
Text(player.playerLabel(.short))
|
|
}
|
|
}
|
|
|
|
func _teamView(_ team: TeamRegistration) -> some View {
|
|
Menu {
|
|
Menu("Toute l'équipe") {
|
|
let players = team.players()
|
|
_actionView(players: players)
|
|
}
|
|
Divider()
|
|
ForEach(team.players()) { player in
|
|
_playerView(player)
|
|
}
|
|
} label: {
|
|
Text(team.teamLabel(.short))
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
MenuWarningView(teams: [], contactType: .constant(nil))
|
|
}
|
|
|