//
//  AgendaDestination.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 01/03/2024.
//

import Foundation
import SwiftUI

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

    enum ViewStyle {
        case list
        case calendar
    }
    
    var localizedTitleKey: String {
        switch self {
        case .activity:
            return "En cours"
        case .history:
            return "Terminé"
        case .tenup:
            return "Tenup"
        }
    }
    
    func selectionLabel() -> String {
        localizedTitleKey
    }
    
    var systemImage: String {
        switch self {
        case .activity:
            return "squares.leading.rectangle"
        case .history:
            return "book.closed"
        case .tenup:
            return "tennisball"
        }
    }
    
    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,+)
        }
    }
    
    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: .yellow)
            } else {
                return nil
            }
        }
    }
}
