//
//  PlayerStatView.swift
//  DouShouQi_App
//
//  Created by étudiant on 31/05/2024.
//

import SwiftUI

struct PlayerStatView: View {
    var player: PlayerVM

    var body: some View {
        VStack {
            if let image = UIImage(contentsOfFile: player.player.photo) {
                Image(uiImage: image)
                    .resizable()
                    .frame(width: 100, height: 100)
                    .clipShape(Circle())
                    .padding(.top, 10)
            } else {
                Image(systemName: "person.circle.fill")
                    .resizable()
                    .frame(width: 100, height: 100)
                    .clipShape(Circle())
                    .foregroundColor(.gray)
                    .padding(.top, 10)
            }

            Text(player.player.name)
                .font(.largeTitle)
                .foregroundColor(.black)
                .padding(.top, 10)

            VStack(alignment: .leading, spacing: 10) {
                HStack {
                    Image(systemName: "trophy.fill")
                    Text("Win : \(player.win)")
                        .font(.title2)
                }
                HStack {
                    Image(systemName: "xmark.circle.fill")
                    Text("Loose : \(player.loose)")
                        .font(.title2)
                }
                HStack {
                    Image(systemName: "chart.line.uptrend.xyaxis")
                    Text("Win Rate : \(String(format: "%.2f", Double(player.win) / Double(player.win + player.loose) * 100))%")
                        .font(.title2)
                }
                HStack {
                    Image(systemName: "list.number")
                    Text("Rank : 3")
                        .font(.title2)
                }
            }
            .padding()
            Spacer()
        }
    }
}
