//
//  PlayerStatisticView.swift
//  PadelClub
//
//  Created by razmig on 06/11/2024.
//

import SwiftUI
import LeStorage

struct PlayerStatisticView: View {
    let player: PlayerRegistration
    
    let teams: [TeamRegistration]
    
    init(player: PlayerRegistration) {
        self.player = player
        self.teams = DataStore.shared.tournaments.filter { $0.isDeleted == false }.flatMap({ $0.unsortedTeams() }).filter({ $0.includes(player: player)
        })
    }
    
    
    var body: some View {
        List {
            Section {
                LabeledContent {
                    Text(teams.count.formatted())
                } label: {
                    Text("Participations")
                }
                LabeledContent {
                    Text(teams.filter({ $0.walkOut }).count.formatted())
                } label: {
                    Text("Forfaits")
                }
            }
        }
        .headerProminence(.increased)
        .navigationTitle("Statistiques")
        .navigationBarTitleDisplayMode(.inline)
        .toolbarBackground(.visible, for: .navigationBar)
    }
}
