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

import SwiftUI

struct MatchTeamDetailView: View {
    let match: Match
    
    var body: some View {
        NavigationStack {
            let tournament = match.currentTournament()
            List {
                if let teamOne = match.team(.one) {
                    _teamDetailView(teamOne, inTournament: tournament)
                }
                if let teamTwo = match.team(.two) {
                    _teamDetailView(teamTwo, inTournament: tournament)
                }
            }
            .headerProminence(.increased)
            .tint(.master)
        }
        .presentationDetents([.fraction(0.66)])
    }
    
    @ViewBuilder
    private func _teamDetailView(_ team: TeamRegistration, inTournament tournament: Tournament?) -> some View {
        Section {
            ForEach(team.players()) { player in
                EditablePlayerView(player: player, editingOptions: [.licenceId, .name, .payment])
            }
        } header: {
            TeamHeaderView(team: team, teamIndex: tournament?.indexOf(team: team), tournament: nil)
        }
    }

}

//#Preview {
//    MatchTeamDetailView(match: Match.mock())
//}
