(i=>{null!=window.astra&&(astraSingleProductAjax={quick_view_enable:astra.shop_quick_view_enable||!1,ajax_add_to_cart_enable:astra.single_product_ajax_add_to_cart||!1,init:function(){this._bind()},_bind:function(){astraSingleProductAjax.ajax_add_to_cart_enable&&i(document).on("click","body.single-product .product:not(.product-type-external) button.single_add_to_cart_button, #sticky-add-to-cart .single_add_to_cart_button",astraSingleProductAjax._processAjaxRequest),astraSingleProductAjax.quick_view_enable&&i(document.body).on("click","#ast-quick-view-content .product:not(.product-type-external) button.single_add_to_cart_button",astraSingleProductAjax._processAjaxRequest),i(document.body).on("added_to_cart",astraSingleProductAjax._updateButton),i("form.variations_form").on("woocommerce_variation_has_changed",astraSingleProductAjax._updateSaleBadge)},_processAjaxRequest:function(a){a.preventDefault();var r,t,e,d,n,o,a=i(this).closest("form");return!a[0].checkValidity()||(r=i(this),t=a.find('input[name="add-to-cart"]').val()||a.find('input[name="product_id"]').val()||i(this).val()||"",e=a.find('input[name="variation_id"]').val()||"",a.hasClass("variations_form")&&!e)?(a[0].reportValidity(),!1):void(r.hasClass("disabled")||(r.removeClass("added"),r.addClass("loading"),n=a.find('input[name="quantity"]').val(),a.find(".woocommerce-grouped-product-list-item").length&&(d=a.find("input.qty"),n=[],i.each(d,function(a,t){var e=(e=i(this).attr("name")).replace("quantity[","").replace("]","");e=parseInt(e),i(this).val()&&(n[e]=i(this).val())})),o=new FormData(a[0]),a.serialize(),o.append("action","astra_add_cart_single_product"),o.append("add-to-cart",t),e&&o.append("variation_id",e),n&&(Array.isArray(n)?i.each(n,function(a,t){o.append("quantity["+a+"]",t)}):o.append("quantity",n)),i.ajax({url:astra.ajax_url,type:"POST",data:o,contentType:!1,processData:!1,success:function(a){if(!a||0===a.length)return location.reload(),!1;if(i(document.body).trigger("wc_fragment_refresh"),i(document.body).trigger("added_to_cart",[a.fragments,a.cart_hash,r]),astra.is_single_product){let a=i("#astra-mobile-cart-drawer");"slide_in_cart"===astra.add_to_cart_options_single&&a&&i(document.body).one("wc_fragments_refreshed",function(){a.addClass("active"),i("html").addClass("ast-mobile-cart-active")}),"redirect_cart_page"===astra.add_to_cart_options_single&&window.open(astra.cart_url,"_self"),"redirect_checkout_page"===astra.add_to_cart_options_single&&window.open(astra.checkout_url,"_self"),"default"===astra.add_to_cart_options_single&&"undefined"!=typeof wc_add_to_cart_params&&"yes"===wc_add_to_cart_params.cart_redirect_after_add&&(window.location=wc_add_to_cart_params.cart_url)}},error:function(a,t,e){r.removeClass("loading"),a.responseJSON&&a.responseJSON.error?alert(a.responseJSON.error):alert("Could not add product to cart. Please try again.")}})))},_updateButton:function(a,t,e,r){r=void 0!==r&&r,i("button.single_add_to_cart_button").length&&(i(r).removeClass("loading"),i(r).addClass("added"),astra.is_cart||0!==i(r).parent().find(".added_to_cart").length||i(r).after(' <a href="'+astra.cart_url+'" class="added_to_cart wc-forward" title="'+astra.view_cart+'">'+astra.view_cart+"</a>"),i(document.body).trigger("wc_cart_button_updated",[r]))},_updateSaleBadge:function(a){var t,e,r=i(this),d=r.find(".variation_id").val();""!=d&&"sale-percentage"==(r=r.closest(".product-type-variable").find("span.onsale")).data("notification")&&void 0!==(t=r.data("sale"))[d]&&(e=(e=r.data("sale-per-text")).replace("[value]",t[d]),r.text(e))}},i(function(){astraSingleProductAjax.init()}))})(jQuery);