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/Match/PlayerBlockView.swift

87 lines
2.3 KiB

//
// PlayerBlockView.swift
// Padel Tournament
//
// Created by Razmig Sarkissian on 25/11/2023.
//
import SwiftUI
struct PlayerBlockView: View {
var match: Match
let team: TeamData
let color: Color
let width: CGFloat
var names: [String]? {
match.teamNames(team)
}
var hasWon: Bool {
match.teamWon(team)
}
var hideScore: Bool {
match.hasWalkoutTeam()
}
var isWalkOut: Bool {
match.teamWalkOut(team)
}
var scores: [String] {
match.teamScore(team)?.score?.components(separatedBy: ",") ?? []
}
private func _defaultLabel() -> String {
team.localizedLabel()
}
var body: some View {
HStack {
VStack(alignment: .leading) {
if let names {
ForEach(names, id: \.self) { name in
Text(name).lineLimit(1)
}
} else {
ZStack(alignment: .leading) {
VStack {
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 {
ForEach(scores.indices, id: \.self) { index in
let string = scores[index]
if 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)
}
}
}
}
}
}