//
//  PlayerListView.swift
//  DouShouQiIOS
//
//  Created by Pierre FERREIRA on 13/05/2024.
//

import SwiftUI
import DouShouQiModel

struct PlayerListView: View {
    var playerStub : StubbedPlayers = StubbedPlayers()
    var body: some View {
        //NavigationStack {
            ZStack {
                Rectangle().fill(Color.bgColor).ignoresSafeArea()
                VStack {
                    /*Text("Classement des joueurs")
                        .scaleEffect(1.75)*/
                    
                    List(playerStub.getStubbedPlayer()) { player in
                        NavigationLink {
                            PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
                                                            Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
                                                            Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
                                                            Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
                                                        ],
                                       playerVm: player) //mettre player plus tard
                        } label:{Text("pif")}
                    }.navigationDestination(for: String.self) { name in
                        PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
                            Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
                            Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
                            Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
                                                    ],
                                   playerVm: PlayerVM(with: Player(withName: "Toto", andId: .player2)!)) //mettre player plus tard
                    }
                    .navigationTitle("Leaderboard")

                    
                    
                    
                    List {
                        NavigationLink{
                            PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
                                                            Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
                                                            Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
                                                            Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
                                                        ],
                                       playerVm: PlayerVM(with: Player(withName: "Billy", andId: .player2)!)) //mettre player plus tard

                        } label:{Text("pif")}
                        
                        NavigationLink("Billy", value: "Billyname")
                        NavigationLink("Bob", value: "Bob")
                        NavigationLink("Bromingo", value: "Bromingo")
                    }
                    .navigationDestination(for: String.self) { name in
                        PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
                            Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
                            Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
                            Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
                                                    ],
                                   playerVm: PlayerVM(with: Player(withName: "Toto", andId: .player2)!)) //mettre player plus tard
                    }
                    .navigationTitle("Leaderboard")
                }

                VStack {
                    Spacer()
                    NavButton("Menu", destinationView: {MainMenuView()}, hideBackButton: true)
                    .padding(.bottom, 20)
                }
            }
        //}
    }
}

struct PlayerListView_Previews: PreviewProvider {
    static var previews: some View {
        PlayerListView()
    }
}
