@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using ReviewApp.Constants
@using ReviewApp.Models
@model ReviewApp.Models.ViewModels.IndexViewModel

@inject SignInManager<User> SignInManager

<h1>Товары:</h1>

<div class="over-flow-for-goods">
    @foreach (var good in Model.Goods)
    {
        <div class="good">
            <div>
                <div class="flex-display gapped-flex-display">
                    <div>
                        <img class="good-image-small" src="/Files/GoodImage/@good.Good.Id" alt="Товар" />
                    </div>
                    <div>
                        <div class="good-name">@good.Good.Name</div>
                        <div class="good-description">@good.Good.Description</div>
                    </div>

                    <div class="time-span-and-add-comment-link">
                        <div >@good.Good.TimeSpan</div>
                        <a asp-controller="Home" asp-action="AddComment" asp-route-id="@good.Good.Id" title="Добавить отзыв">Добавить отзыв</a>
                    </div>

                    @if (SignInManager.IsSignedIn(User) && User.IsInRole(GlobalConstants.AdminRoleName))
                    {
                        <form asp-controller="Home" asp-action="RemoveGood" method="post">
                            <button class="delete-button" type="submit">
                                <img class="delete-button-picture" src="/images/delete.png" alt="x"/>
                            </button>

                            <input type="hidden" name="id" value="@good.Good.Id"/>
                            @Html.AntiForgeryToken()
                        </form>
                    }
                </div>
            </div>
                    
            <div class="empty-div"></div>
                <div class="max-width">
                    <div class="last-comment">
                        
                        @if (@good.LastComment == null)
                        {
                            <div>Отзывов ещё нет, ваш станет первым!</div>
                        }
                        else
                        {
                            <div class="display-flex">
                                <div>@good.LastComment.Content</div>
                                <div class="margin-left-bottom-auto">@good.LastComment.CreationTime</div>
                            </div>
                            <div class="flex-display">
    
                                @for (int i = 0; i < @good.LastComment.Rating; i++)
                                {
                                    <div class="star-used">&#11088;</div>
                                }
    
                                @if (@good.LastComment.Rating != 0)
                                {
                                    @for (int i = 0; i < 5 - @good.LastComment.Rating; i++)
                                    {
                                        <div class="star-not-used">&#11088;</div>
                                    }
                                }
                            </div>
                        }
                    </div>
                    <a asp-controller="Home" asp-action="Comments" asp-route-goodId="@good.Good.Id" title="Показать еще">Показать еще</a>
                </div>
        </div>
    }
</div>

@if (SignInManager.IsSignedIn(User) && User.IsInRole(GlobalConstants.AdminRoleName))
{
    <a asp-controller="Home" asp-action="AddGood" title="Добавить товар">Добавить товар</a>
}