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.
259 lines
11 KiB
259 lines
11 KiB
//
|
|
// MatchSummaryView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 23/03/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MatchSummaryView: View {
|
|
var match: Match
|
|
let matchViewStyle: MatchViewStyle
|
|
|
|
var entrantLabelOne: String {
|
|
"match.longLabelTeamOne"
|
|
}
|
|
|
|
var entrantLabelTwo: String {
|
|
"match.longLabelTeamTwo"
|
|
}
|
|
|
|
var color: Color {
|
|
matchViewStyle == .plainStyle ? Color(uiColor: .tertiaryLabel) : Color(uiColor: .secondaryLabel)
|
|
}
|
|
|
|
var width: CGFloat {
|
|
matchViewStyle == .plainStyle ? 1 : 2
|
|
}
|
|
|
|
var body: some View {
|
|
matchSummaryView
|
|
// .contextMenu {
|
|
// ForEach(match.teamScores) { entrant in
|
|
// if let team = entrant.team, team.orderedPlayers.count > 2 {
|
|
// NavigationLink {
|
|
// PlayerPickerView(match: match, team: team)
|
|
// } label: {
|
|
// if let teamTitle = team.entrant?.brand?.title {
|
|
// Text(teamTitle).foregroundStyle(.secondary)
|
|
// } else {
|
|
// let index = match.orderedEntrants.firstIndex(where: { $0 == entrant }) ?? 0
|
|
// Text("Équipe \(index + 1)")
|
|
// }
|
|
// if match.players(from: team).isEmpty {
|
|
// Text("Choisir la paire")
|
|
// } else {
|
|
// Text("Modifier la paire")
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
|
|
@ViewBuilder
|
|
var matchSummaryView: some View {
|
|
VStack(alignment: .leading) {
|
|
if matchViewStyle != .plainStyle {
|
|
HStack {
|
|
if match.isGroupStage() && matchViewStyle != .feedStyle {
|
|
if let groupStage = match.groupStageObject, matchViewStyle == .standardStyle {
|
|
Text(groupStage.groupStageTitle())
|
|
}
|
|
Text(match.matchTitle())
|
|
} else if let currentTournament = match.currentTournament() {
|
|
if matchViewStyle == .feedStyle {
|
|
//tournamentHeaderView(currentTournament)
|
|
} else if matchViewStyle != .sectionedStandardStyle {
|
|
Text(match.matchTitle(.short))
|
|
}
|
|
}
|
|
if matchViewStyle == .standardStyle || matchViewStyle == .sectionedStandardStyle
|
|
{
|
|
Spacer()
|
|
if let court = match.court, match.hasEnded() == false {
|
|
Spacer()
|
|
Text("Terrain #\(court)")
|
|
}
|
|
}
|
|
}
|
|
.lineLimit(1)
|
|
}
|
|
|
|
if matchViewStyle != .feedStyle {
|
|
HStack(spacing: 0) {
|
|
VStack(alignment: .leading, spacing: matchViewStyle == .plainStyle ? 8 : 0) {
|
|
PlayerBlockView(match: match, team: .one, color: color, width: width)
|
|
.padding(matchViewStyle == .plainStyle ? 0 : 8)
|
|
if width == 1 {
|
|
Divider()
|
|
} else {
|
|
Divider().frame(height: width).overlay(color)
|
|
}
|
|
PlayerBlockView(match: match, team: .two, color: color, width: width)
|
|
.padding(matchViewStyle == .plainStyle ? 0 : 8)
|
|
}
|
|
}
|
|
.overlay {
|
|
if matchViewStyle != .plainStyle {
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.stroke(color, lineWidth: 2)
|
|
}
|
|
}
|
|
|
|
if matchViewStyle != .plainStyle {
|
|
HStack {
|
|
Spacer()
|
|
MatchDateView(match: match, showPrefix: matchViewStyle == .tournamentResultStyle ? true : false)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.padding(.vertical, matchViewStyle != .plainStyle ? 8 : 0)
|
|
.monospacedDigit()
|
|
}
|
|
|
|
@ViewBuilder
|
|
func tournamentHeaderView(_ currentTournament: Tournament) -> some View {
|
|
VStack(alignment: .leading) {
|
|
// HStack {
|
|
// ZStack(alignment: .leading) {
|
|
// Text("Poule 9").font(.title3).bold().opacity(0)
|
|
// Text(currentTournament.tournamentLevel.localizedLabel)
|
|
// }
|
|
// if let tournamentTitle = currentTournament.title, tournamentTitle.isEmpty == false {
|
|
// Text(tournamentTitle)
|
|
// }
|
|
//
|
|
// Spacer()
|
|
// if let startDate = match.startDate {
|
|
// if let endDate = match.endDate {
|
|
// let duration = Duration(
|
|
// secondsComponent: Int64(endDate.timeIntervalSince(startDate)),
|
|
// attosecondsComponent: 0
|
|
// ).formatted(.units(allowed: [.hours, .minutes], width: .narrow))
|
|
// Text("durée")
|
|
// } else if startDate.timeIntervalSinceNow < 0 {
|
|
// Text("en cours")
|
|
// } else {
|
|
// Text("prévu à")
|
|
// }
|
|
// } else {
|
|
// if let endDate = match.endDate {
|
|
// Text("a fini à")
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// HStack {
|
|
// ZStack(alignment: .leading) {
|
|
// Text("Poule 9").opacity(0)
|
|
// Text(match.shortTitleLabel)
|
|
// }
|
|
// if let score = match.score, match.hasEnded() {
|
|
// Text(score.label)
|
|
// } else if match.fieldIndex > 0 {
|
|
// Text("terrain #\(match.fieldIndex)")
|
|
// }
|
|
//
|
|
// Spacer()
|
|
// if let startDate = match.startDate {
|
|
// if let endDate = match.endDate {
|
|
// let duration = Duration(
|
|
// secondsComponent: Int64(endDate.timeIntervalSince(startDate)),
|
|
// attosecondsComponent: 0
|
|
// ).formatted(.units(allowed: [.hours, .minutes], width: .narrow))
|
|
// Text(duration)
|
|
// } else if startDate.timeIntervalSinceNow < 0 {
|
|
// Text(startDate, style: .timer)
|
|
// } else {
|
|
// Text(startDate.formatted(date: .omitted, time: .shortened))
|
|
// }
|
|
// } else {
|
|
// if let endDate = match.endDate {
|
|
// Text(endDate.formatted(.dateTime.hour().minute()))
|
|
// }
|
|
// }
|
|
// }
|
|
// .font(.title3)
|
|
//
|
|
// HStack {
|
|
// ZStack(alignment: .leading) {
|
|
// Text("Poule 9").font(.title3).bold().opacity(0)
|
|
// VStack {
|
|
// Text(currentTournament.tournamentCategory.localizedLabel)
|
|
// }
|
|
// }
|
|
//
|
|
// if let winnerEntrant = match.winnerEntrant {
|
|
// Text(winnerEntrant.longLabelPlayerOne)
|
|
// } else if match.isBracketMatch {
|
|
// Text(match.subtitleLabel)
|
|
// } else if let entrantOne = match.entrantOne()?.team?.firstPairLastNames {
|
|
// Text(entrantOne)
|
|
// }
|
|
//
|
|
// Spacer()
|
|
// if let startDate = match.startDate {
|
|
// if let endDate = match.endDate {
|
|
// let duration = Duration(
|
|
// secondsComponent: Int64(endDate.timeIntervalSince(startDate)),
|
|
// attosecondsComponent: 0
|
|
// ).formatted(.units(allowed: [.hours, .minutes], width: .narrow))
|
|
// Text(startDate.formatted(.dateTime.hour().minute()))
|
|
// } else if startDate.timeIntervalSinceNow < 0 {
|
|
// Text(startDate.formatted(.dateTime.hour().minute()))
|
|
// } else {
|
|
// Text(startDate.formatted(.dateTime.day().month()))
|
|
// }
|
|
// } else {
|
|
// if let endDate = match.endDate {
|
|
// Text("début")
|
|
// }
|
|
// }
|
|
// }
|
|
// .font(.caption)
|
|
//
|
|
// HStack {
|
|
// ZStack(alignment: .leading) {
|
|
// Text("Poule 9").font(.title3).bold().opacity(0)
|
|
// VStack {
|
|
// Text(currentTournament.tournamentAgeLabel)
|
|
// }
|
|
// }
|
|
//
|
|
// if let winnerEntrant = match.winnerEntrant {
|
|
// Text(winnerEntrant.longLabelPlayerTwo)
|
|
// } else if match.isBracketMatch {
|
|
// } else if let entrant = match.entrantTwo()?.team?.firstPairLastNames {
|
|
// Text(entrant)
|
|
// }
|
|
//
|
|
// Spacer()
|
|
// if let startDate = match.startDate {
|
|
// if let endDate = match.endDate {
|
|
// let duration = Duration(
|
|
// secondsComponent: Int64(endDate.timeIntervalSince(startDate)),
|
|
// attosecondsComponent: 0
|
|
// ).formatted(.units(allowed: [.hours, .minutes], width: .narrow))
|
|
// Text(startDate.formatted(.dateTime.day().month().year()))
|
|
// } else if startDate.timeIntervalSinceNow < 0 {
|
|
// Text(startDate.formatted(.dateTime.day().month().year()))
|
|
// } else {
|
|
// Text(startDate.formatted(.dateTime.year()))
|
|
// }
|
|
// } else {
|
|
// if let endDate = match.endDate {
|
|
// Text("non défini")
|
|
// }
|
|
// }
|
|
// }
|
|
// .font(.caption)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
MatchSummaryView(match: Match.mock(), matchViewStyle: .standardStyle)
|
|
}
|
|
|