//
//  MultiCourtPickerView.swift
//  PadelClub
//
//  Created by razmig on 11/10/2024.
//

import SwiftUI

struct MultiCourtPickerView: View {
    @Bindable var matchScheduler: MatchScheduler
    @Environment(Tournament.self) var tournament: Tournament
    
    var body: some View {
        List {
            ForEach(tournament.courtsAvailable(), id: \.self) { courtIndex in
                LabeledContent {
                    Button {
                        if matchScheduler.courtsAvailable.contains(courtIndex) {
                            matchScheduler.courtsAvailable.remove(courtIndex)
                        } else {
                            matchScheduler.courtsAvailable.insert(courtIndex)
                        }
                    } label: {
                        if matchScheduler.courtsAvailable.contains(courtIndex) {
                            Image(systemName: "checkmark.circle.fill")
                        }
                    }
                } label: {
                    Text(tournament.courtName(atIndex: courtIndex))
                }
            }
        }
        .navigationTitle("Terrains disponibles")
        .toolbarBackground(.visible, for: .navigationBar)
        .environment(\.editMode, Binding.constant(EditMode.active))
    }
}
