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.
117 lines
2.7 KiB
117 lines
2.7 KiB
//
|
|
// AgendaDestination.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 01/03/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
import TipKit
|
|
|
|
enum AgendaDestination: Int, CaseIterable, Identifiable, Selectable, Equatable {
|
|
var id: Int { self.rawValue }
|
|
|
|
static func == (lhs: AgendaDestination, rhs: AgendaDestination) -> Bool {
|
|
return lhs.id == rhs.id
|
|
}
|
|
|
|
case activity
|
|
case history
|
|
case tenup
|
|
case around
|
|
|
|
var localizedTitleKey: String {
|
|
switch self {
|
|
case .activity:
|
|
return "En cours"
|
|
case .history:
|
|
return "Terminé"
|
|
case .tenup:
|
|
return "Tenup"
|
|
case .around:
|
|
return "Autour"
|
|
}
|
|
}
|
|
|
|
func associatedTip() -> (any Tip)? {
|
|
switch self {
|
|
case .around:
|
|
return PlayerTournamentSearchTip()
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func selectionLabel(index: Int) -> String {
|
|
localizedTitleKey
|
|
}
|
|
|
|
func systemImage() -> String? {
|
|
switch self {
|
|
case .around:
|
|
return "location.magnifyingglass"
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func badgeValue() -> Int? {
|
|
switch self {
|
|
case .activity:
|
|
DataStore.shared.tournaments.filter { $0.endDate == nil && $0.isDeleted == false && FederalDataViewModel.shared.isTournamentValidForFilters($0) }.count
|
|
case .history:
|
|
DataStore.shared.tournaments.filter { $0.endDate != nil && FederalDataViewModel.shared.isTournamentValidForFilters($0) }.count
|
|
case .tenup:
|
|
FederalDataViewModel.shared.filteredFederalTournaments.map { $0.tournaments.count }.reduce(0,+)
|
|
case .around:
|
|
nil
|
|
|
|
}
|
|
}
|
|
|
|
func badgeValueColor() -> Color? {
|
|
switch self {
|
|
case .history:
|
|
return .green
|
|
case .tenup:
|
|
return .logoBackground
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func badgeImage() -> Badge? {
|
|
switch self {
|
|
case .activity:
|
|
return nil
|
|
case .history:
|
|
return nil
|
|
case .tenup:
|
|
if FederalDataViewModel.shared.federalTournaments.isEmpty {
|
|
return .custom(systemName: "exclamationmark.circle.fill", color: .logoYellow)
|
|
} else {
|
|
return nil
|
|
}
|
|
case .around:
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
enum ViewStyle {
|
|
case list
|
|
case calendar
|
|
}
|
|
|
|
struct ViewStyleKey: EnvironmentKey {
|
|
static let defaultValue: ViewStyle = .list
|
|
}
|
|
|
|
extension EnvironmentValues {
|
|
var viewStyle: ViewStyle {
|
|
get { self[ViewStyleKey.self] }
|
|
set { self[ViewStyleKey.self] = newValue }
|
|
}
|
|
}
|
|
|