@model IEnumerable<TournamentDto>
@{
    ViewData["Title"] = "Tournaments";
}

<div class="d-flex justify-content-between align-items-center mb-3">
    <h2>Tournaments</h2>
    <a asp-action="Create" class="btn btn-primary">Create Tournament</a>
</div>

<partial name="_Notification" />

<table class="table table-striped table-hover">
    <thead class="table-dark">
        <tr>
            <th>Name</th>
            <th>Dates</th>
            <th>Status</th>
            <th>Events</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var t in Model)
        {
            <tr>
                <td>
                    <a asp-action="Details" asp-route-id="@t.TournamentId" class="text-decoration-none fw-bold">@t.Name</a>
                    @if (t.IsArchived) { <span class="badge bg-secondary ms-1">Archived</span> }
                </td>
                <td>@t.StartDate.ToString("MMM d") - @t.EndDate.ToString("MMM d, yyyy")</td>
                <td>
                    @{
                        var statusClass = t.Status switch {
                            TournamentStatus.Draft => "bg-secondary",
                            TournamentStatus.Registration => "bg-info",
                            TournamentStatus.InProgress => "bg-primary",
                            TournamentStatus.Completed => "bg-success",
                            _ => "bg-dark"
                        };
                    }
                    <span class="badge @statusClass">@t.Status</span>
                </td>
                <td>@t.EventCount</td>
                <td>
                    <a asp-action="Edit" asp-route-id="@t.TournamentId" class="btn btn-sm btn-outline-primary">Edit</a>
                    <a asp-action="Details" asp-route-id="@t.TournamentId" class="btn btn-sm btn-outline-info">Details</a>
                </td>
            </tr>
        }
    </tbody>
</table>
