@model LANCommander.Models.GameLookupResultsViewModel

@{
    ViewData["Title"] = "Games";
}
<div class="container-xl">
    <div class="page-header d-print-none">
        <div class="row align-items-center">
            <div class="col">
                <div class="page-pretitle">@Model.Search</div>
                <h2 class="page-title">
                    Game Lookup
                </h2>
            </div>
        </div>
    </div>
</div>

<div class="page-body">
    <div class="container-xl">
        <div class="row row-cards">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">Results</h3>
                    </div>
                    @if (Model.Results.Count() == 0)
                    {
                        <div class="card-body">
                            <p>No games could be found with the search "@Model.Search".</p>
                        </div>
                    }
                    else
                    {
                        <div class="card-body">
                            @if (Model.Results.Count() > 1)
                            {
                                <p>There was a total of @Model.Results.Count() games that matched the search "@Model.Search" in IGDB's database.</p>
                            }
                            else
                            {
                                <p>Only one game matched the search "@Model.Search" in IGDB's database.</p>
                            }
                        </div>
                        <form>
                            <div class="table-responsive">
                                <table class="table table-vcenter table-mobile-md card-table">
                                    <thead>
                                        <tr>
                                            <th>
                                                Title
                                            </th>
                                            <th>
                                                Release Date
                                            </th>
                                            <th>
                                                Developers
                                            </th>
                                            <th></th>
                                        </tr>
                                    </thead>

                                    <tbody>
                                        @foreach (var item in Model.Results)
                                        {
                                            <tr>
                                                <td>
                                                    @Html.DisplayFor(modelItem => item.Title)
                                                </td>
                                                <td>
                                                    @Html.DisplayFor(modelItem => item.ReleasedOn)
                                                </td>
                                                <td>
                                                    @String.Join(", ", item.Developers.Select(d => d.Name))
                                                </td>
                                                <td>
                                                    <div class="btn-list flex-nowrap justify-content-end">
                                                        <a asp-action="Add" asp-route-igdbid="@item.IGDBId" class="btn btn-ghost-primary">Select</a>
                                                    </div>
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </form>

                    }

                    <div class="card-footer">
                        <div class="d-flex">
                            <a class="btn btn-ghost-primary" asp-action="Add" asp-controller="Games">Go Back</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>