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/Tournament/Screen/TournamentSettingsView.swift

98 lines
2.6 KiB

//
// TournamentSettingsView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 22/03/2024.
//
import SwiftUI
enum TournamentSettings: Identifiable, Selectable, Equatable {
static func == (lhs: TournamentSettings, rhs: TournamentSettings) -> Bool {
return lhs.id == rhs.id
}
case status
case general
case club(Tournament)
case matchFormats
case onlineRegistration(Tournament)
var id: String { String(describing: self) }
func selectionLabel(index: Int) -> String {
switch self {
case .status:
return "Statut"
case .matchFormats:
return "Formats"
case .general:
return "Général"
case .club:
return "Terrains"
case .onlineRegistration:
return "Inscriptions"
}
}
func badgeValue() -> Int? {
switch self {
case .club(let tournament):
return tournament.courtCount
default:
return nil
}
}
func badgeValueColor() -> Color? {
return .logoBackground
}
func badgeImage() -> Badge? {
switch self {
case .onlineRegistration(let tournament):
if tournament.enableOnlineRegistration {
return .checkmark
}
default:
return nil
}
return nil
}
}
struct TournamentSettingsView: View {
@State private var selectedDestination: TournamentSettings? = .general
@Environment(Tournament.self) var tournament: Tournament
private func destinations() -> [TournamentSettings] {
[.general, .club(tournament), .matchFormats, .onlineRegistration(tournament)]
}
var body: some View {
VStack(spacing: 0) {
GenericDestinationPickerView(selectedDestination: $selectedDestination, destinations: destinations(), nilDestinationIsValid: false)
switch selectedDestination! {
case .status:
TournamentStatusView(tournament: tournament)
case .matchFormats:
TournamentMatchFormatsSettingsView()
case .general:
TournamentGeneralSettingsView(tournament: tournament)
case .onlineRegistration:
RegisrationSetupView(tournament: tournament)
case .club:
TournamentClubSettingsView()
}
}
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar)
.navigationTitle("Réglages du tournoi")
}
}
//#Preview {
// TournamentSettingsView()
//}