@using System.Security.Claims;
@model IEnumerable<AllGenreViewModel>
@{
    ViewData["Title"] = "Genres";
}

<h1 class="text-center">Genres</h1>
<hr />
<div class="row row-cols-1 row-cols-md-5 g-4">
    @{
        @foreach (var group in Model.GroupBy(g => g.Name?[0]).OrderBy(g => g.Key))
        {
            <div class="col">
                <div class="card text-bg-info h-100">
                    <h2 class="text-center">@group.Key</h2>
                    <ul style="display: inline-block; text-align: left;">
                        @foreach (AllGenreViewModel genre in group.OrderBy(g => g.Name))
                        {
                            <li class="genre-item">
                                <a style="text-decoration: none; color: midnightblue"
                                   asp-controller="Composition"
                                   asp-action="All"
                                   asp-route-selectedGenres="@genre.Id"
                                   asp-route-currentPage=""
                                   asp-route-searchTerm=""
                                   asp-route-dateSorting=""
                                   asp-route-ratingSorting="">
                                    @genre.Name (@genre.CompositionCount)
                                    @if (User?.Identity?.IsAuthenticated ?? false)
                                    {
                                        <form method="post" asp-controller="User" asp-action="FavoriteGenre" asp-route-genreId="@genre.Id">
                                            <input type="submit" class="btn-sm" value="&#11088;" />
                                        </form>
                                    }
                                </a>
                            </li>
                        }
                    </ul>
                </div>
            </div>
        }
    }
</div>