//
//  TournamentButtonView.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 03/03/2024.
//

import SwiftUI

struct TournamentButtonView: View {
    @Environment(NavigationViewModel.self) private var navigation
    let tournament: Tournament

    var body: some View {
        Button {
            if navigation.isTournamentAlreadyOpenInOrganizer(tournament) {
                navigation.closeTournamentFromOrganizer(tournament)
            } else {
                navigation.openTournamentInOrganizer(tournament)
            }
        } label: {
            TournamentCellView(tournament: tournament, displayStyle: .short)
                .padding(8)
                .overlay(
                    RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.black, lineWidth: 2)
                )
                .fixedSize(horizontal: false, vertical: true)
        }
        .overlay(alignment: .top) {
            if navigation.isTournamentAlreadyOpenInOrganizer(tournament) {
                Image(systemName: "ellipsis")
                    .offset(y: -10)
            }
        }

    }
}
