@model ProductDetailsModel.AddToCartModel
@using Nop.Core.Domain.Orders
@if (Model.UpdatedShoppingCartItemId > 0)
{
    <input asp-for="UpdatedShoppingCartItemId" type="hidden" />
}
@if (!Model.DisableBuyButton || Model.CustomerEntersPrice)
{
<div class="add-to-cart">
    @if (Model.CustomerEntersPrice)
    {
        <div class="customer-entered-price">
            <div class="price-input">
                <div class="row mb-3">
                    <label asp-for="CustomerEnteredPrice" asp-postfix=":" class="enter-price-label col-sm-12 col-md-4 col-lg-4 col-xl-4 col-form-label pr-0"></label>
                    @*round price*@
                    <div class="col-sm-12 col-md-8 col-lg-8 col-xl-8">
                        <input asp-for="CustomerEnteredPrice" value="@Convert.ToInt32(Math.Ceiling(Model.CustomerEnteredPrice))" class="enter-price-input form-control" />
                    </div>
                </div>
                <div class="price-range alert alert-info">
                    <strong>@Model.CustomerEnteredPriceRange</strong>
                </div>
            </div>
        </div>
    }
    @if (!string.IsNullOrEmpty(Model.MinimumQuantityNotification))
    {
        <div class="min-qty-notification alert alert-info"><strong>@Model.MinimumQuantityNotification</strong></div>
    }
    @if (!Model.DisableBuyButton)
    {
        <div class="add-to-cart-panel">
            <label asp-for="EnteredQuantity" asp-postfix=":" class="qty-label col-sm-12 col-md-1 col-lg-1 col-xl-1 col-form-label pl-0"></label>
            @if (Model.AllowedQuantities.Count > 0)
            {
                <select asp-for="EnteredQuantity" asp-items="Model.AllowedQuantities" id="product_enteredQuantity_@Model.ProductId" class="qty-dropdown form-control custom-select" aria-label=@T("Products.Qty.AriaLabel")></select>
                <script asp-location="Footer">
                    $(function () {
                        $("#product_enteredQuantity_@Model.ProductId").on("change", function () {
                            var data = {
                                productId: @Model.ProductId,
                                quantity: $('#product_enteredQuantity_@Model.ProductId').find(":selected").text()
                            };
                            $(document).trigger({ type: "product_quantity_changed", changedData: data });
                        });
                    });
                </script>
            }
            else
            {
                <input asp-for="EnteredQuantity" id="product_enteredQuantity_@Model.ProductId" class="qty-input form-control" type="text" aria-label=@T("Products.Qty.AriaLabel") />
                <script asp-location="Footer">
                    //when a customer clicks 'Enter' button we submit the "add to cart" button (if visible)
                    $(function () {
                        $("#@Html.IdFor(model => model.EnteredQuantity)").on("keydown", function(event) {
                            if (event.keyCode == 13) {
                                $("#add-to-cart-button-@Model.ProductId").trigger("click");
                                return false;
                            }
                        });

                        $("#product_enteredQuantity_@Model.ProductId").on("input propertychange paste", function () {
                            var data = {
                                productId: @Model.ProductId,
                                quantity: $('#product_enteredQuantity_@Model.ProductId').val()
                            };
                            $(document).trigger({ type: "product_quantity_changed", changedData: data });
                        });
                        });
                </script>
            }
            @{
                var addToCartText = "";
                if (Model.UpdatedShoppingCartItemId > 0 && Model.UpdateShoppingCartItemType.HasValue && Model.UpdateShoppingCartItemType.Value == ShoppingCartType.ShoppingCart)
                {
                    addToCartText = T("ShoppingCart.AddToCart.Update").Text;
                }
                else
                {
                    addToCartText = T("ShoppingCart.AddToCart").Text;
                    if (Model.IsRental)
                    {
                        addToCartText = T("ShoppingCart.Rent").Text;
                    }
                    if (Model.AvailableForPreOrder)
                    {
                        addToCartText = T("ShoppingCart.PreOrder").Text;
                    }
                }
                <button type="button" id="add-to-cart-button-@Model.ProductId" class="button-1 btn btn-primary add-to-cart-button" data-productid="@Model.ProductId" onclick="AjaxCart.addproducttocart_details('@Url.RouteUrl("AddProductToCart-Details", new {productId = Model.ProductId, shoppingCartTypeId = (int) ShoppingCartType.ShoppingCart})', '#product-details-form');return false;">@addToCartText</button>
            }
        </div>
        if (!string.IsNullOrEmpty(Model.PreOrderAvailabilityStartDateTimeUserTime))
        {
            <div class="pre-order-availability-date">
                <label>@T("ShoppingCart.PreOrderAvailability"):</label>
                @Html.Raw(Model.PreOrderAvailabilityStartDateTimeUserTime)
            </div>
        }
    }
    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductDetailsAddInfo, additionalData = Model })
</div>
}