ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Views/Shared/_ProductBox.cshtml
@model ProductOverviewModel
@{
    //prepare "Add to cart" AJAX link
    string addtocartlink = "";
    string addtowishlistlink = "";
    string quickviewurl = Url.RouteUrl("QuickView-Product", new { productId = Model.Id });

    var shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart;
    var quantity = 1;
    if (!Model.ShowQty)
    {
        if (Model.ProductPrice.ForceRedirectionAfterAddingToCart)
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, quantity = quantity, forceredirection = Model.ProductPrice.ForceRedirectionAfterAddingToCart });
        }
        else
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, quantity = quantity });
        }
        addtowishlistlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = (int)ShoppingCartType.Wishlist, quantity = quantity });
    }
    else
    {
        if (Model.ProductPrice.ForceRedirectionAfterAddingToCart)
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, forceredirection = Model.ProductPrice.ForceRedirectionAfterAddingToCart });
        }
        else
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId });
        }
        addtowishlistlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = (int)ShoppingCartType.Wishlist });
    }
    var addtocomparelink = Url.RouteUrl("AddProductToCompare", new { productId = Model.Id });
}

@await Component.InvokeAsync("Widget", new { widgetZone = "productbox_before_content", additionalData = Model})

<div class="product-box grid-box animation lazyload" data-productid="@Model.Id">
    <div class="box-unvisible"></div>
    <div class="picture-container">
        <a class="picture" href="@Url.RouteUrl("Product", new { SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title">
            <picture>
                <source media="(max-width: 767px)" picture-id="@Model.DefaultPictureModel.Id" picture-size="400" />
                <source media="(max-width: 575px)" picture-id="@Model.DefaultPictureModel.Id" picture-size="300" />
                <source media="(max-width: 420px)" picture-id="@Model.DefaultPictureModel.Id" picture-size="200" />
                <img class="img-fluid" alt="@Model.DefaultPictureModel.AlternateText" src="@Model.DefaultPictureModel.ImageUrl" title="@Model.DefaultPictureModel.Title" />
            </picture>
        </a>
        @if (!string.IsNullOrEmpty(Model.SecondPictureModel.ImageUrl))
        {
            <div class="hover-img">
                <a class="picture" href="@Url.RouteUrl("Product", new { SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title">
                    <picture>
                        <source media="(max-width: 480px)" picture-id="@Model.SecondPictureModel.Id" picture-size="300" />
                        <source media="(max-width: 575px)" picture-id="@Model.SecondPictureModel.Id" picture-size="300" />
                        <source media="(max-width: 420px)" picture-id="@Model.SecondPictureModel.Id" picture-size="200" />
                        <img class="img-fluid" alt="@Model.SecondPictureModel.AlternateText" src="@Model.SecondPictureModel.ImageUrl" />
                    </picture>
                </a>
                <div class="additional-info">
                    @if (Model.ShowQty)
                    {
                        var qtyId = "addtocart_" + @Model.Id + "_EnteredQuantity";
                        <input class="form-control input-group-addon catalog-quantity" type="number" id="@qtyId" name="@qtyId" value="1">
                    }
                    <button type="button" value="@T("Products.QuickView")" title="@T("Products.QuickView")" class="btn btn-secondary" data-toggle="modal" data-target="ModalQuickView" onclick="AjaxCart.quickview_product('@quickviewurl')">
                        <span class="mdi mdi-magnify"></span>
                        <span>@T("Products.QuickView")</span>
                    </button>
                </div>
            </div>
        }
        else
        {
            <div class="hover-img no-img">
                <div class="additional-info">
                    @if (Model.ShowQty)
                    {
                        var qtyId = "addtocart_" + @Model.Id + "_EnteredQuantity";
                        <input class="form-control input-group-addon catalog-quantity" type="number" id="@qtyId" name="@qtyId" value="1">
                    }
                    <button type="button" value="@T("Products.QuickView")" title="@T("Products.QuickView")" class="btn btn-secondary" data-toggle="modal" data-target="ModalQuickView" onclick="AjaxCart.quickview_product('@quickviewurl')">
                        <span class="mdi mdi-magnify mr-1"></span>
                        <span>@T("Products.QuickView")</span>
                    </button>
                </div>
            </div>
        }
    </div>
    <div class="labels">
        @if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
        {
            <span class="product-discount badge product-box-label">
                <span>-@(Convert.ToInt32((1 - Model.ProductPrice.PriceValue / Model.ProductPrice.OldPriceValue) * 100))%</span>
            </span>
        }
        @if (!string.IsNullOrEmpty(Model.Flag))
        {
            <span class="product-box-label badge bg-info text-white">@Model.Flag</span>
        }
    </div>
    <div class="product-info">
        <div class="top">
            @if (Model.ReviewOverviewModel.AllowCustomerReviews)
            {
                int ratingPercent = 0;
                if (Model.ReviewOverviewModel.TotalReviews != 0)
                {
                    ratingPercent = ((Model.ReviewOverviewModel.RatingSum * 100) / Model.ReviewOverviewModel.TotalReviews) / 5;
                }
                <div class="ratings">
                    <div class="rating-box">
                        <div class="rating" style="width: @(ratingPercent)%">
                        </div>
                    </div>
                </div>
            }
            <div class="title">
                <h3 class="mb-0">
                    <a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })">@Model.Name</a>
                </h3>
            </div>
            @if (Model.ShowSku && !string.IsNullOrEmpty(Model.Sku))
            {
                <span class="sku">@Model.Sku</span>
            }
            <div class="prices-rating">
                <div class="prices @if (Model.ProductType == ProductType.Reservation) { <text>reservation-price</text> } ">
                    @if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
                    {
                        <div class="old-price price">
                            @Model.ProductPrice.OldPrice
                        </div>
                    }
                    @if (Model.ProductType != ProductType.Auction)
                    {
                        <div class="actual-price price">
                            @Model.ProductPrice.Price
                        </div>
                    }
                    else
                    {
                        <div class="actual-price price">
                            @(Model.ProductPrice.HighestBidValue > 0 ? Model.ProductPrice.HighestBid : Model.ProductPrice.StartPrice)
                        </div>
                    }
                </div>
            </div>
            @if (Model.ProductPrice.DisplayTaxShippingInfo)
            {
                var inclTax = Model.TaxDisplayType == TaxDisplayType.IncludingTax;
                <div class="tax-shipping-info">
                    @T(inclTax ? "Products.Price.TaxShipping.InclTax" : "Products.Price.TaxShipping.ExclTax", Url.RouteUrl("Topic", new { SeName = TopicSeNameConstants.Shippinginfo }))
                </div>
            }
        </div>
        <div class="bottom">
            @if (Model.ProductType == ProductType.Auction)
            {
                @if (Model.EndTime.HasValue)
                {
                    <div class="countdown-box p-sm-2 p-1 bg-light">
                        @if (Model.EndTime > DateTime.UtcNow)
                        {
                            <label class="d-inline-block mb-0">@T("AddToCart.Timeleft"): </label>
                            <div class="d-inline-block" data-countdown="@Model.EndTime.Value.ToString("yyyy-MM-dd HH:mm UTC")"></div>
                        }
                        else
                        {
                            <div class="d-inline-flex flex-wrap justify-content-center">
                                <label class="ended-label">@T("ShoppingCart.Auctionends"):</label>
                                <div class="count-date">@Model.EndTimeLocalTime.Value.ToString()</div>
                            </div>
                        }
                    </div>
                }
            }
            @if (Model.SpecificationAttributeModels.Any())
            {
                <div class="spec-container">
                    @{
                        var group = Model.SpecificationAttributeModels.GroupBy(x => x.SpecificationAttributeName);
                    }
                    <table>
                        <tbody>
                            @foreach (var item in group)
                            {
                                <tr class="spec">
                                    <td>
                                        <div class="spec-name">
                                            @{
                                                var groupList = item.ToList();
                                            }
                                            @groupList[0].SpecificationAttributeName:
                                        </div>
                                    </td>
                                    <td>
                                        @{
                                            var groupList2 = item.ToList();
                                        }
                                        <div class="spec-value">
                                            @foreach (var spec in groupList)
                                            {
                                                <span>
                                                    @Html.Raw(spec.ValueRaw)
                                                </span>
                                            }
                                        </div>
                                    </td>

                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            }
            @if (Model.ProductAttributeModels.Any())
            {
                <div class="attr-container">
                    <table>
                        <tbody>
                            @foreach (var item in Model.ProductAttributeModels)
                            {
                                <tr class="attr">
                                    <td>
                                        <div class="attr-name">
                                           @item.Name
                                        </div>
                                    </td>
                                    <td>
                                        <div class="attr-value">
                                            @foreach (var spec in item.Values)
                                            {
                                                switch (item.AttributeControlType)
                                                {
                                                    case AttributeControlType.DropdownList:
                                                    case AttributeControlType.RadioList:
                                                    case AttributeControlType.Checkboxes:
                                                    case AttributeControlType.ReadonlyCheckboxes:
                                                        <div class="name">
                                                            @Html.Raw(spec.Name)
                                                        </div>
                                                        break;
                                                    case AttributeControlType.ColorSquares:
                                                        <div class="name color-container" title="@spec.Name">
                                                            <span class="color" style="background-color:@spec.ColorSquaresRgb;">&nbsp;</span>
                                                        </div>
                                                        break;
                                                    case AttributeControlType.ImageSquares:
                                                        <div class="name image-container">
                                                            <img src="@spec.ImageSquaresPictureModel?.ImageUrl" />
                                                        </div>
                                                        break;
                                                    default:
                                                        break;
                                                }
                                            }
                                        </div>
                                    </td>

                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            }
            <div class="desc">
                @Html.Raw(Model.ShortDescription)
            </div>
            <div class="buttons btn-group">
                @if (!Model.ProductPrice.DisableWishlistButton && Model.ProductType == ProductType.SimpleProduct)
                {
                    <button type="button" data-toggle="title" title="@T("ShoppingCart.AddToWishlist")" class="btn btn-secondary" onclick="AjaxCart.addproducttocart_catalog('@addtowishlistlink', '@Model.ShowQty', '@Model.Id');return false;">
                        <span class="mdi mdi-heart-outline">
                        </span>
                        <span class="sr-only">AddToWishlist</span>
                    </button>
                }
                @if (!Model.ProductPrice.DisableBuyButton)
                {
                    var addToCartText = T("ShoppingCart.AddToCart").Text;
                    if (Model.ProductType == ProductType.Reservation)
                    {
                        addToCartText = T("ShoppingCart.Reservation").Text;
                    }
                    if (Model.ProductPrice.AvailableForPreOrder)
                    {
                        addToCartText = T("ShoppingCart.PreOrder").Text;
                    }
                    <button type="button" class="btn btn-info justify-content-center w-100" onclick="AjaxCart.addproducttocart_catalog('@addtocartlink', '@Model.ShowQty', '@Model.Id');return false;">
                        <span class="mdi mdi-cart-outline"></span>
                        <span class="add-cart-text">@(addToCartText)</span>
                        <span class="sr-only">AddToCart</span>
                    </button>
                }
                else
                {
                    if (Model.ProductType == ProductType.Auction)
                    {
                        var addToCartText = T("ShoppingCart.Bids").Text;
                        <button type="button" class="btn btn-info justify-content-center w-100" onclick="AjaxCart.addproducttocart_catalog('@addtocartlink', 'false', '@Model.Id');return false;">
                            <span class="mdi mdi-gavel"></span>
                            <span class="add-cart-text">@(addToCartText)</span>
                            <span class="sr-only">AddToCart</span>
                        </button>
                    }
                }
                @if (!Model.ProductPrice.DisableAddToCompareListButton && Model.ProductType == ProductType.SimpleProduct)
                {
                    <button type="button" data-tooltip="title" title="@T("ShoppingCart.AddToCompareList")" class="btn btn-secondary" onclick="AjaxCart.addproducttocomparelist('@addtocomparelink');return false;">
                        <span class="sr-only">AddToCompareList</span>
                        <span class="mdi mdi-repeat"></span>
                    </button>
                }
            </div>
        </div>
    </div>
</div>
