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/Planning/SchedulerView.swift

85 lines
2.5 KiB

//
// SchedulerView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 07/04/2024.
//
import SwiftUI
extension GroupStage: Schedulable {
func titleLabel() -> String {
self.groupStageTitle()
}
}
extension Round: Schedulable {
func titleLabel() -> String {
self.roundTitle()
}
}
struct SchedulerView: View {
var tournament: Tournament
var destination: ScheduleDestination
var body: some View {
List {
switch destination {
case .scheduleGroupStage:
ForEach(tournament.groupStages()) {
_schedulerView($0)
}
case .scheduleBracket:
ForEach(tournament.rounds()) { round in
_schedulerView(round)
}
default:
EmptyView()
}
}
.headerProminence(.increased)
}
func _schedulerView(_ schedulable: any Schedulable) -> some View {
Section {
NavigationLink {
Group {
if let round = schedulable as? Round {
RoundScheduleEditorView(round: round)
.environment(tournament)
}
else if let groupStage = schedulable as? GroupStage {
GroupStageScheduleEditorView(groupStage: groupStage)
}
}
.navigationTitle(schedulable.titleLabel())
} label: {
LabeledContent {
Text(schedulable.matchFormat.format).font(.largeTitle)
} label: {
if let startDate = schedulable.getStartDate() {
Text(startDate.formatted(.dateTime.hour().minute())).font(.largeTitle)
Text(startDate.formatted(.dateTime.weekday().day(.twoDigits).month().year()))
} else {
Text("Aucun horaire")
}
}
}
if let round = schedulable as? Round {
NavigationLink {
LoserRoundScheduleEditorView(upperRound: round)
.environment(tournament)
} label: {
Text("Match de classement \(round.roundTitle(.short))")
}
}
} header: {
Text(schedulable.titleLabel())
}
.headerProminence(.increased)
}
}
#Preview {
SchedulerView(tournament: Tournament.mock(), destination: .scheduleBracket)
}