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.
 
 
PadelClub/PadelClub/Views/Team/TeamRowView.swift

126 lines
3.8 KiB

//
// TeamRowView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 24/03/2024.
//
import SwiftUI
struct TeamRowView: View {
@EnvironmentObject var dataStore: DataStore
var team: TeamRegistration
var teamIndex: Int?
var teamPosition: TeamPosition? = nil
var displayCallDate: Bool = false
var displayRestingTime: Bool = false
var body: some View {
LabeledContent {
TeamWeightView(team: team, teamPosition: teamPosition, teamIndex: teamIndex)
} label: {
VStack(alignment: .leading) {
TeamHeadlineView(team: team)
TeamView(team: team)
}
if displayCallDate {
TeamCallDateView(team: team)
}
if displayRestingTime {
TeamRestingView(team: team)
}
}
}
struct TeamRestingView: View {
let team: TeamRegistration
@ViewBuilder
var body: some View {
if let restingTime = team.restingTime()?.timeIntervalSinceNow, let value = Date.hourMinuteFormatter.string(from: restingTime * -1) {
if restingTime > -300 {
Text("vient de finir")
.font(.footnote)
.foregroundStyle(.secondary)
} else {
Text("en repos depuis " + value)
.font(.footnote)
.foregroundStyle(.secondary)
}
}
}
}
struct TeamView: View {
let team: TeamRegistration
var body: some View {
if let name = team.name, name.isEmpty == false {
Text(name).foregroundStyle(.secondary).font(.footnote)
if team.players().isEmpty {
Text("Aucun joueur")
} else {
CompactTeamView(team: team)
}
} else {
if team.players().isEmpty == false {
CompactTeamView(team: team)
} else {
Text("Place réservée")
Text("Place réservée")
}
}
}
}
struct TeamHeadlineView: View {
let team: TeamRegistration
var body: some View {
HStack {
if let groupStage = team.groupStageObject() {
HStack {
Text(groupStage.groupStageTitle(.title))
if let finalPosition = groupStage.finalPosition(ofTeam: team) {
Text((finalPosition + 1).ordinalFormatted())
}
}
} else if let round = team.initialRound() {
Text(round.roundTitle(.wide))
}
if let wildcardLabel = team.wildcardLabel() {
Text(wildcardLabel).italic().foregroundStyle(.red).font(.caption)
}
}
}
}
struct TeamCallDateView: View {
let team: TeamRegistration
var body: some View {
if let callDate = team.callDate {
Text("Déjà convoquée \(callDate.localizedDate())")
.foregroundStyle(.logoRed)
.italic()
.font(.caption)
} else {
Text("Pas encore convoquée")
.foregroundStyle(.logoRed)
.italic()
.font(.caption)
}
}
}
struct CompactTeamView: View {
let team: TeamRegistration
var body: some View {
ForEach(team.players()) { player in
Text(player.playerLabel()).lineLimit(1).truncationMode(.tail)
}
}
}
}