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.
109 lines
4.1 KiB
109 lines
4.1 KiB
//
|
|
// TeamRegistration+Extensions.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Laurent Morvillier on 27/08/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import PadelClubData
|
|
|
|
extension TeamRegistration {
|
|
|
|
func getPhoneNumbers() -> [String] {
|
|
return players().compactMap { $0.phoneNumber }.filter({ $0.isMobileNumber() })
|
|
}
|
|
|
|
func playersPasteData(_ exportFormat: ExportFormat = .rawText) -> String {
|
|
switch exportFormat {
|
|
case .rawText:
|
|
return players().map { $0.pasteData(exportFormat) }.joined(separator: exportFormat.newLineSeparator())
|
|
case .csv:
|
|
return players().map { [$0.pasteData(exportFormat), isWildCard() ? "WC" : $0.computedRank.formatted() ].joined(separator: exportFormat.separator()) }.joined(separator: exportFormat.separator())
|
|
}
|
|
}
|
|
|
|
func formattedInscriptionDate(_ exportFormat: ExportFormat = .rawText) -> String? {
|
|
switch exportFormat {
|
|
case .rawText:
|
|
if let registrationDate {
|
|
return "Inscrit le " + registrationDate.formatted(.dateTime.weekday().day().month().hour().minute())
|
|
} else {
|
|
return nil
|
|
}
|
|
case .csv:
|
|
if let registrationDate {
|
|
return registrationDate.formatted(.dateTime.weekday().day().month().hour().minute())
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
|
|
func formattedSummonDate(_ exportFormat: ExportFormat = .rawText) -> String? {
|
|
|
|
switch exportFormat {
|
|
case .rawText:
|
|
if let callDate {
|
|
return "Convoqué le " + callDate.formatted(.dateTime.weekday().day().month().hour().minute())
|
|
} else {
|
|
return nil
|
|
}
|
|
case .csv:
|
|
if let callDate {
|
|
return callDate.formatted(.dateTime.weekday().day().month().hour().minute())
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
|
|
func pasteData(_ exportFormat: ExportFormat = .rawText, _ index: Int = 0) -> String {
|
|
switch exportFormat {
|
|
case .rawText:
|
|
return [playersPasteData(exportFormat), formattedInscriptionDate(exportFormat), name].compactMap({ $0 }).joined(separator: exportFormat.newLineSeparator())
|
|
case .csv:
|
|
return [index.formatted(), playersPasteData(exportFormat), isWildCard() ? "WC" : weight.formatted()].joined(separator: exportFormat.separator())
|
|
}
|
|
}
|
|
|
|
func positionLabel() -> String? {
|
|
if groupStagePosition != nil { return "Poule" }
|
|
if let initialRound = initialRound() {
|
|
return initialRound.roundTitle()
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func initialRoundColor() -> Color? {
|
|
if walkOut { return Color.logoRed }
|
|
if groupStagePosition != nil { return Color.blue }
|
|
if let initialRound = initialRound(), let colorHex = RoundRule.colors[safe: initialRound.index] {
|
|
return Color(uiColor: .init(fromHex: colorHex))
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func containsExactlyPlayerLicenses(_ playerLicenses: [String?]) -> Bool {
|
|
let arrayOfIds : [String] = unsortedPlayers().compactMap({ $0.licenceId?.strippedLicense?.canonicalVersion })
|
|
let ids : Set<String> = Set<String>(arrayOfIds.sorted())
|
|
let searchedIds = Set<String>(playerLicenses.compactMap({ $0?.strippedLicense?.canonicalVersion }).sorted())
|
|
return ids.hashValue == searchedIds.hashValue
|
|
}
|
|
|
|
@objc
|
|
var canonicalName: String {
|
|
players().map { $0.canonicalName }.joined(separator: " ")
|
|
}
|
|
|
|
func teamLabel(_ displayStyle: DisplayStyle = .wide, twoLines: Bool = false) -> String {
|
|
return players().map { $0.playerLabel(displayStyle) }.joined(separator: twoLines ? "\n" : " & ")
|
|
}
|
|
|
|
func teamLabelRanked(displayRank: Bool, displayTeamName: Bool) -> String {
|
|
[displayTeamName ? name : nil, displayRank ? seedIndex() : nil, displayTeamName ? (name == nil ? teamLabel() : name) : teamLabel()].compactMap({ $0 }).joined(separator: " ")
|
|
}
|
|
|
|
}
|
|
|