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

import SwiftUI

struct TeamWeightView: View {
    var team: TeamRegistration
    var teamPosition: TeamPosition? = nil
    var teamIndex: Int?
    var displayWeight: Bool = true
    
    init(team: TeamRegistration, teamPosition: TeamPosition? = nil) {
        self.team = team
        self.teamPosition = teamPosition
        let tournament = team.tournamentObject()
        self.teamIndex = tournament?.indexOf(team: team)
        self.displayWeight = tournament?.hideWeight() == false
    }

    var body: some View {
        VStack(alignment: .trailing, spacing: 0) {
            if (teamPosition == .one || teamPosition == nil) && displayWeight {
                Text(team.weight.formatted())
                    .monospacedDigit()
                    .font(.caption)
            }
            if let teamIndex {
                Text("#" + (teamIndex + 1).formatted(.number.precision(.integerLength(2...3))))
                    .monospacedDigit()
            }
            if teamPosition == .two && displayWeight {
                Text(team.weight.formatted())
                    .monospacedDigit()
                    .font(.caption)
                
            }
        }
    }
}

//#Preview {
//    TeamWeightView(team: TeamRegistration.mock(), teamPosition: .one)
//}
