@(player: de.knockoutwhist.player.AbstractPlayer, logic: de.knockoutwhist.control.GameLogic, gameId: String)

@main("Tie") {
<div id="tie" class="game-field game-field-background">
    <div class="ingame-stage blur-sides">
        <div class="container py-4">
            <div class="row justify-content-center">
                <div class="col-12 col-md-10 col-lg-8">
                    <div class="card shadow-sm">
                        <div class="card-header text-center">
                            <h3 class="mb-0">Tie Break</h3>
                        </div>
                        <div class="card-body">
                            <div class="mb-3">
                                <p class="card-text">
                                    The last round was tied between:
                                    <span class="ms-1">
                                    @for(players <- logic.playerTieLogic.getTiedPlayers) {
                                        <span class="badge text-bg-secondary me-1">@players</span>
                                    }
                                    </span>
                                </p>
                            </div>

                            @if(player.equals(logic.playerTieLogic.currentTiePlayer())) {
                                @defining(logic.playerTieLogic.highestAllowedNumber()) { maxNum =>
                                    <div class="alert alert-info" role="alert" aria-live="polite">
                                        Pick a number between 1 and @{maxNum + 1}. The resulting card will be your card for the cut.
                                    </div>

                                    <form class="row g-2 align-items-center" method="post" action="@routes.IngameController.playTie(gameId)">
                                        <div class="col-auto">
                                            <label for="tieNumber" class="col-form-label">Your number</label>
                                        </div>
                                        <div class="col-auto">
                                            <input type="number" id="tieNumber" class="form-control" name="tie" min="1" max="@{maxNum + 1}" placeholder="1" required>
                                        </div>
                                        <div class="col-auto">
                                            <button type="submit" class="btn btn-primary">Confirm</button>
                                        </div>
                                    </form>
                                    <h6 class="mt-4 mb-3">Currently Picked Cards</h6>

                                    <div id="cardsplayed" class="row g-3 justify-content-center">
                                        @if(logic.playerTieLogic.getSelectedCard.nonEmpty) {
                                            @for((player, card) <- logic.playerTieLogic.getSelectedCard) {
                                                <div class="col-6">
                                                    <div class="card shadow-sm border-0 h-100 text-center">
                                                        <div class="card-body d-flex flex-column justify-content-between">
                                                            <p class="card-text fw-semibold mb-2 text-primary">@player</p>
                                                            <div class="card-img-top">
                                                            @util.WebUIUtils.cardtoImage(card)
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            }
                                        } else {
                                            <div class="col-12">
                                                <div class="alert alert-info text-center" role="alert">
                                                    <i class="bi bi-info-circle me-2"></i>
                                                    No cards have been selected yet.
                                                </div>
                                            </div>
                                        }
                                    </div>
                                }
                            } else {
                                <div class="alert alert-warning" role="alert" aria-live="polite">
                                    <strong>@logic.playerTieLogic.currentTiePlayer()</strong> is currently picking a number for the cut.
                                </div>

                                <h6 class="mt-4 mb-3">Currently Picked Cards</h6>

                                <div id="cardsplayed" class="row g-3 justify-content-center">
                                    @if(logic.playerTieLogic.getSelectedCard.nonEmpty) {
                                        @for((player, card) <- logic.playerTieLogic.getSelectedCard) {
                                            <div class="col-6 col-sm-4 col-md-3 col-lg-2">
                                                <div class="card shadow-sm border-0 h-100 text-center">
                                                    <div class="card-body d-flex flex-column justify-content-between">
                                                        <p class="card-text fw-semibold mb-2 text-primary">@player</p>
                                                        <div class="card-img-top">
                                                        @util.WebUIUtils.cardtoImage(card)
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        }
                                    } else {
                                        <div class="col-12">
                                            <div class="alert alert-info text-center" role="alert">
                                                <i class="bi bi-info-circle me-2"></i>
                                                No cards have been selected yet.
                                            </div>
                                        </div>
                                    }
                                </div>
                            }

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
}