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/MatchSummaryView.swift

103 lines
3.4 KiB

//
// MatchSummaryView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 23/03/2024.
//
import SwiftUI
struct MatchSummaryView: View {
var match: Match
let matchViewStyle: MatchViewStyle
let matchTitle: String
let roundTitle: String?
let courtName: String?
let spacing: CGFloat
let padding: CGFloat
let color: Color
let width: CGFloat
init(match: Match, matchViewStyle: MatchViewStyle, title: String? = nil) {
self.match = match
self.matchViewStyle = matchViewStyle
self.padding = matchViewStyle == .plainStyle ? 0 : 8
self.spacing = matchViewStyle == .plainStyle ? 8 : 0
self.width = matchViewStyle == .plainStyle ? 1 : 2
self.color = Color(white: 0.9)
if let groupStage = match.groupStageObject {
self.roundTitle = groupStage.groupStageTitle()
} else if let round = match.roundObject {
self.roundTitle = round.roundTitle(matchViewStyle == .feedStyle ? .wide : .short)
} else {
self.roundTitle = nil
}
self.matchTitle = title ?? match.matchTitle(.short)
if match.hasEnded() == false, let court = match.courtName() {
self.courtName = court
} else {
self.courtName = nil
}
}
var body: some View {
VStack(alignment: .leading) {
if matchViewStyle != .plainStyle {
HStack {
if matchViewStyle != .sectionedStandardStyle {
if let roundTitle {
Text(roundTitle).fontWeight(.semibold)
}
if match.groupStage != nil || match.index > 0 {
Text(matchTitle)
}
}
Spacer()
if let courtName, matchViewStyle != .feedStyle {
Spacer()
Text(courtName)
.foregroundStyle(.gray)
.font(.caption)
}
}
.lineLimit(1)
}
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: spacing) {
PlayerBlockView(match: match, teamPosition: .one, color: color, width: width)
.padding(padding)
if width == 1 {
Divider()
} else {
Divider().frame(height: width).overlay(color)
}
PlayerBlockView(match: match, teamPosition: .two, color: color, width: width)
.padding(padding)
}
}
.overlay {
if matchViewStyle != .plainStyle {
RoundedRectangle(cornerRadius: 8)
.stroke(color, lineWidth: 2)
}
}
if matchViewStyle != .plainStyle {
HStack {
Spacer()
MatchDateView(match: match, showPrefix: matchViewStyle == .tournamentResultStyle)
}
}
}
.padding(.vertical, padding)
.monospacedDigit()
}
}
//#Preview {
// MatchSummaryView(match: Match.mock(), matchViewStyle: .standardStyle)
//}