(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();a=i(this).closest("form");if(!a[0].checkValidity())return a[0].reportValidity(),!1;var t,r,e,o=i(this),d=i('input[name="add-to-cart"]').val()||i(this).val()||"",n=i('input[name="variation_id"]').val()||"";o.hasClass("disabled")||(o.removeClass("added"),o.addClass("loading"),r=i('input[name="quantity"]').val(),i(".woocommerce-grouped-product-list-item").length&&(t=i("input.qty"),r=[],i.each(t,function(a,t){var e=(e=i(this).attr("name")).replace("quantity[","").replace("]","");e=parseInt(e),i(this).val()&&(r[e]=i(this).val())})),e=new FormData(a[0]),a.serialize(),e.append("action","astra_add_cart_single_product"),e.append("add-to-cart",d),n&&e.append("variation_id",n),r&&(Array.isArray(r)?i.each(r,function(a,t){e.append("quantity["+a+"]",t)}):e.append("quantity",r)),i.ajax({url:astra.ajax_url,type:"POST",data:e,contentType:!1,processData:!1,success:function(a){if(!a||0===a.length)return location.reload(),!1;i(document.body).trigger("wc_fragment_refresh"),i(document.body).trigger("added_to_cart",[a.fragments,a.cart_hash,o]),astra.is_single_product&&(a=i("#astra-mobile-cart-drawer"),"slide_in_cart"===astra.add_to_cart_options_single&&a&&(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){o.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(' '+astra.view_cart+""),i(document.body).trigger("wc_cart_button_updated",[r]))},_updateSaleBadge:function(a){var t,e,r=i(this),o=r.find(".variation_id").val();""!=o&&"sale-percentage"==(r=r.closest(".product-type-variable").find("span.onsale")).data("notification")&&void 0!==(t=r.data("sale"))[o]&&(e=(e=r.data("sale-per-text")).replace("[value]",t[o]),r.text(e))}},i(function(){astraSingleProductAjax.init()}))})(jQuery);