//
//  PlayerRow.swift
//  DouShouQi_App
//
//  Created by étudiant on 26/05/2024.
//

import Foundation
import SwiftUI

struct PlayerRow: View {
    var player: PlayerVM
    @Binding var players: PlayersVM
    
    @State private var showDetailView = false

    var body: some View {
        HStack {
            if let image = UIImage(contentsOfFile: player.player.photo) {
                Image(uiImage: image)
                    .resizable()
                    .frame(width: 50, height: 50)
                    .clipShape(Circle())
            } else {
                Image(systemName: "person.circle.fill")
                    .resizable()
                    .frame(width: 50, height: 50)
                    .clipShape(Circle())
                    .foregroundColor(.gray)
            }
            
            VStack(alignment: .leading) {
                Text(player.player.name)
                    .font(.headline)
                Text("Victoires : \(player.win)  Défaites : \(player.loose)")
                    .font(.subheadline)
            }
            Spacer()
            Button(action: {
                showDetailView.toggle()
            }) {
                Image(systemName: "info.circle")
                    .foregroundColor(.blue)
            }
            .sheet(isPresented: $showDetailView) {
                PlayerStatView(player: player)
            }
        }
        .padding()
        .background(Color.white)
        .cornerRadius(10)
        .shadow(radius: 1)
    }
}
