@{
    var title = ViewBag.ScoringTitle as string ?? "Scoring";
    var controller = ViewBag.ScoringController as string ?? "TrackEvent";
    var targets = ViewBag.ScoringTargets as IEnumerable<TournamentEventLevelDto> ?? Enumerable.Empty<TournamentEventLevelDto>();
    ViewData["Title"] = title;
}

<h2>@title</h2>
<p class="text-muted">Select an event level to score.</p>
<hr />

@if (!targets.Any())
{
    <div class="alert alert-info">
        No event levels are available for scoring yet. Add event levels to an active tournament from the
        <a asp-controller="Tournament" asp-action="Index">Tournaments</a> page.
    </div>
}
else
{
    @foreach (var grp in targets.GroupBy(t => new { t.TournamentId, t.TournamentName }))
    {
        <div class="card shadow-sm mb-3">
            <div class="card-header text-white" style="background-color: #003366;">
                <h5 class="mb-0">@grp.Key.TournamentName</h5>
            </div>
            <div class="card-body p-0">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr><th>Event</th><th>Level</th><th>Registrations</th><th></th></tr>
                    </thead>
                    <tbody>
                        @foreach (var t in grp.OrderBy(x => x.EventName).ThenBy(x => x.EventLevelName))
                        {
                            <tr>
                                <td>@t.EventName</td>
                                <td>@t.EventLevelName</td>
                                <td>@t.RegistrationCount</td>
                                <td class="text-end">
                                    <a asp-controller="@controller" asp-action="Index" asp-route-tournamentEventLevelId="@t.TournamentEventLevelId" class="btn btn-sm btn-outline-success">Score</a>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
    }
}
