@using PhoneStore.Repositories.Interfaces
@using Microsoft.AspNetCore.Identity
@model PhoneStore.ViewModels.PhoneViewModels.PhoneViewModel
@inject IFeedbackRepository _feedbackRepository;
@inject UserManager<User> _userManager;
@{
    ViewBag.Title = "Подробная информация";
    Layout = "_Layout";
}

<h2>@Model.Name</h2>
<div class="card mb-3">
    <div class="container">
        <img class="card-img-top w-50" src="~/@Model.Image" alt="Card image cap">
        <div class="card-body">
            <h5 class="card-title">@Model.Brand.Name</h5>
            <p class="card-text">@(Model.Price.ToString("C2"))</p>
        </div>
        @if (User.Identity.IsAuthenticated)
        {
            if (!_feedbackRepository.CheckFeedbackExists(int.Parse(_userManager.GetUserId(User)), Model.Id))
            {
                <form class="mb-3" id="feedbackForm">
                    <div class="form-group">
                        <label for="text">Добавьте отзыв о телефоне</label>
                        <input type="text" class="form-control" id="text" placeholder="Минимальная длина отзыва 10 символов">
                        <input type="text" hidden name="phoneId" id="@Model.Id">
                        <button class="my-3 btn btn-outline-warning" type="submit">Отправить</button>
                    </div>
                </form>
            }
        }
        else if(!User.Identity.IsAuthenticated)
        {
            <a asp-action="Login" asp-controller="Account">Авторизируйтесь для добавления отзыва</a>
        }
    </div>
</div>
<div id="feedbacks">
    @foreach (var feedBack in Model.Feedbacks)
    {
        await Html.RenderPartialAsync("PartialViews/FeedbackPartialView", feedBack);
    }
</div>
@{
    await Html.RenderPartialAsync("PartialViews/EditFeedbackModalPartial");
}
