//
//  TeamHeaderView.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 18/04/2024.
//

import SwiftUI

struct TeamHeaderView: View {
    var team: TeamRegistration
    var teamIndex: Int?
    var tournament: Tournament?
    
    var body: some View {
        HStack(spacing: 16.0) {
            if let teamIndex {
                VStack(alignment: .leading, spacing: 0) {
                    Text("Rang").font(.caption)
                    Text("#" + (teamIndex + 1).formatted())
                }
            }
            
            if team.unsortedPlayers().isEmpty == false {
                if tournament?.hideWeight() == false, team.weight > 0 {
                    VStack(alignment: .leading, spacing: 0) {
                        Text("Poids").font(.caption)
                        Text(team.weight.formatted())
                    }
                }
                if let name = team.name {
                    VStack(alignment: .leading, spacing: 0) {
                        Text("Nom de l'équipe").font(.caption)
                        Text(name)
                    }
                }
            }
            Spacer()
            VStack(alignment: .trailing, spacing: 0) {
                if team.walkOut {
                    Text("").font(.caption)
                    Text("WO")
                } else if let teamIndex, let tournament {
                    if team.isWildCard() {
                        Text("wildcard").font(.caption).italic()
                    } else {
                        Text("").font(.caption)
                    }
                    Text(tournament.cutLabel(index: teamIndex))
                }
            }
        }
    }
}

//#Preview {
//    TeamHeaderView(team: TeamRegistration.mock(), teamIndex: 1, tournament: nil)
//}
