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.
53 lines
1.6 KiB
53 lines
1.6 KiB
//
|
|
// LoserBracketView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 04/04/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct LoserBracketView: View {
|
|
@EnvironmentObject var dataStore: DataStore
|
|
let loserRounds: [Round]
|
|
|
|
@ViewBuilder
|
|
var body: some View {
|
|
if let first = loserRounds.first {
|
|
List {
|
|
ForEach(loserRounds) { loserRound in
|
|
_loserRoundView(loserRound)
|
|
let childLoserRounds = loserRound.loserRounds()
|
|
if childLoserRounds.isEmpty == false {
|
|
let uniqueChildRound = childLoserRounds.first
|
|
if childLoserRounds.count == 1, let uniqueChildRound {
|
|
_loserRoundView(uniqueChildRound)
|
|
} else if let uniqueChildRound {
|
|
NavigationLink {
|
|
LoserBracketView(loserRounds: childLoserRounds)
|
|
} label: {
|
|
Text(uniqueChildRound.roundTitle())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle(first.roundTitle())
|
|
}
|
|
}
|
|
|
|
private func _loserRoundView(_ loserRound: Round) -> some View {
|
|
Section {
|
|
ForEach(loserRound.playedMatches()) { match in
|
|
MatchRowView(match: match, matchViewStyle: .standardStyle)
|
|
}
|
|
} header: {
|
|
Text(loserRound.roundTitle())
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
LoserBracketView(loserRounds: [Round.mock()])
|
|
.environmentObject(DataStore.shared)
|
|
}
|
|
|