//
//  PlayersWithoutContactView.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 26/06/2024.
//

import SwiftUI

struct PlayersWithoutContactView: View {
    @Environment(Tournament.self) var tournament: Tournament
    let players: [PlayerRegistration]
    
    var body: some View {
        Section {
            let withoutEmails = players.filter({ $0.email?.isEmpty == true })
            DisclosureGroup {
                ForEach(withoutEmails) { player in
                    NavigationLink {
                        PlayerDetailView(player: player)
                            .environment(tournament)
                    } label: {
                        ImportedPlayerView(player: player)
                    }
                }
            } label: {
                LabeledContent {
                    Text(withoutEmails.count.formatted())
                } label: {
                    Text("Joueurs sans email")
                }
            }

            let withoutPhones = players.filter({ $0.phoneNumber?.isEmpty == true })
            DisclosureGroup {
                ForEach(withoutPhones) { player in
                    NavigationLink {
                        PlayerDetailView(player: player)
                            .environment(tournament)
                    } label: {
                        ImportedPlayerView(player: player)
                    }
                }
            } label: {
                LabeledContent {
                    Text(withoutPhones.count.formatted())
                } label: {
                    Text("Joueurs sans téléphone")
                }
            }
        } header: {
            Text("Joueurs sans moyen de contact")
        }
    }
}
