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.
110 lines
3.4 KiB
110 lines
3.4 KiB
//
|
|
// PlayerBlockView.swift
|
|
// Padel Tournament
|
|
//
|
|
// Created by Razmig Sarkissian on 25/11/2023.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct PlayerBlockView: View {
|
|
@State var match: Match
|
|
let teamPosition: TeamPosition
|
|
let team: TeamRegistration?
|
|
let color: Color
|
|
let width: CGFloat
|
|
let teamScore: TeamScore?
|
|
let isWalkOut: Bool
|
|
|
|
init(match: Match, teamPosition: TeamPosition, color: Color, width: CGFloat) {
|
|
self.match = match
|
|
self.teamPosition = teamPosition
|
|
let theTeam = match.team(teamPosition)
|
|
self.team = theTeam
|
|
self.color = color
|
|
self.width = width
|
|
let theTeamScore = match.teamScore(ofTeam: theTeam)
|
|
self.teamScore = theTeamScore
|
|
self.isWalkOut = theTeamScore?.isWalkOut() == true
|
|
}
|
|
|
|
var names: [String]? {
|
|
match.teamNames(team)
|
|
}
|
|
|
|
var hasWon: Bool {
|
|
match.teamWon(team)
|
|
}
|
|
|
|
var hideScore: Bool {
|
|
match.hasWalkoutTeam()
|
|
}
|
|
|
|
var scores: [String] {
|
|
teamScore?.score?.components(separatedBy: ",") ?? []
|
|
}
|
|
|
|
private func _defaultLabel() -> String {
|
|
teamPosition.localizedLabel()
|
|
}
|
|
|
|
var body: some View {
|
|
HStack {
|
|
VStack(alignment: .leading) {
|
|
if let names {
|
|
if let teamScore, teamScore.luckyLoser != nil, match.isLoserBracket == false {
|
|
Text("Repêchée").italic().font(.caption)
|
|
}
|
|
|
|
if let name = team?.name {
|
|
Text(name).font(.title3)
|
|
} else {
|
|
ForEach(names, id: \.self) { name in
|
|
Text(name).lineLimit(1)
|
|
}
|
|
}
|
|
} else {
|
|
ZStack(alignment: .leading) {
|
|
VStack {
|
|
if let name = team?.name {
|
|
Text(name).font(.title3)
|
|
} else {
|
|
Text("longLabelPlayerOne").lineLimit(1)
|
|
Text("longLabelPlayerTwo").lineLimit(1)
|
|
}
|
|
}
|
|
.opacity(0)
|
|
Text(_defaultLabel()).foregroundStyle(.secondary).lineLimit(1)
|
|
}
|
|
}
|
|
}
|
|
.bold(hasWon)
|
|
Spacer()
|
|
if hasWon {
|
|
Image(systemName: "trophy")
|
|
} else if isWalkOut {
|
|
Text("WO")
|
|
}
|
|
|
|
if hideScore == false && scores.isEmpty == false {
|
|
ForEach(scores.indices, id: \.self) { index in
|
|
if let string = scores[safe: index], string.isEmpty == false {
|
|
if width == 1 {
|
|
Divider()
|
|
} else {
|
|
Divider().frame(width: width).overlay(color)
|
|
}
|
|
Text(string)
|
|
.font(.title3)
|
|
.frame(maxWidth: 20)
|
|
.scaledToFill()
|
|
.minimumScaleFactor(0.5)
|
|
.lineLimit(1)
|
|
}
|
|
}
|
|
} else if let team {
|
|
TeamWeightView(team: team, teamPosition: teamPosition)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|