jQuery(document).ready(function(h){"use strict";h("body"),h(".add-request-quote-button");var f=h(document).find(".widget_ywraq_list_quote, .widget_ywraq_mini_list_quote"),w="undefined"!=typeof ywraq_frontend&&ywraq_frontend.block_loader,_="undefined"!=typeof ywraq_frontend&&ywraq_frontend.allow_out_of_stock,l="undefined"!=typeof ywraq_frontend&&ywraq_frontend.allow_only_on_out_of_stock,t=(h(".yith-ywraq-item-remove"),h(".shipping_address")),e=h(".woocommerce-billing-fields"),s=document.location.href,a=h(document).find("#yith-ywrq-table-list"),c={message:null,overlayCSS:{background:"#fff",opacity:.7},ignoreIfBlocked:!0},_="yes"==_,l="yes"==l;0<a.length&&ywraq_frontend.raq_table_refresh_check&&h.post(s,function(t){var e;""!=t&&(e=h("<div></div>").html(t).find("#yith-ywrq-table-list"),h("#yith-ywrq-table-list").html(e.html()),h(document).trigger("ywraq_table_reloaded"))}),h(document).on("ywraq_table_reloaded, yith_wwraq_removed_successfully, yith_check_table",function(){0==h(document).find("#yith-ywrq-table-list").length&&h(document).find(".yith-ywraq-before-table .wc-backward").hide()}),h(document).trigger("yith_check_table"),h.fn.yith_ywraq_variations=function(){var i,o,r,d,s,c,e,t=h(document).find("form.variations_form");t.length&&void 0!==t.data("product_id")&&(i=t.data("product_id").toString().replace(/[^0-9]/g,""),o=h(".add-to-quote-"+i).find(".yith-ywraq-add-button"),r=o.find("a.add-request-quote-button"),d=h(".yith_ywraq_add_item_product-response-"+i),s=h(".yith_ywraq_add_item_response-"+i),c=h(".yith_ywraq_add_item_browse-list-"+i),e=function(){r.show().addClass("disabled"),o.show().removeClass("hide").removeClass("addedd"),d.hide().removeClass("show"),s.hide().removeClass("show"),c.hide().removeClass("show"),(l&&_||l)&&r.hide()},t.on("found_variation",function(t,e){var a=""+h(".add-to-quote-"+i).attr("data-variation"),n=!0;d.hide().removeClass("show"),_?l&&e.is_in_stock&&(n=!1):e.is_in_stock||(n=!1),n?(r.show().removeClass("disabled"),o.show().removeClass("hide").removeClass("addedd")):(r.hide().addClass("disabled"),o.hide().removeClass("show").removeClass("addedd")),s.hide().removeClass("show"),c.hide().removeClass("show"),-1!==a.indexOf(""+e.variation_id)&&n?(r.hide(),s.show().removeClass("hide"),c.show().removeClass("hide")):n&&(r.show().removeClass("disabled"),o.show().removeClass("hide").removeClass("addedd"),s.hide().removeClass("show"),c.hide().removeClass("show"))}),t.on("reset_data",function(t){e()}),e())},h(".variations_form").each(function(){h(this).yith_ywraq_variations()}),h(document).on("qv_loader_stop",function(t){h(".variations_form").each(function(){h(this).yith_ywraq_variations()})}),h.fn.yith_ywraq_refresh_button=function(){var t=h('[name|="product_id"]').val();h(".add-to-quote-"+t).find("a.add-request-quote-button").parents(".yith-ywraq-add-to-quote");if(!h('[name|="variation_id"]').length)return!1},h.fn.yith_ywraq_refresh_button();var p=!1;h(document).on("click",".add-request-quote-button",function(t){t.preventDefault();var e=h(this),a=e.closest(".yith-ywraq-add-to-quote"),n="ac",i="";if(e.hasClass("outofstock")?window.alert(ywraq_frontend.i18n_out_of_stock):e.hasClass("disabled")&&window.alert(ywraq_frontend.i18n_choose_a_variation),!(e.hasClass("disabled")||e.hasClass("outofstock")||p)){if(h(".grouped_form").length){var o=0;if(h(".grouped_form input.qty").each(function(){o=Math.floor(h(this).val())+o}),0==o)return void alert(ywraq_frontend.select_quantity)}if("undefined"==typeof(i=e.closest(".cart").length?e.closest(".cart"):a.siblings(".cart").first().length?a.siblings(".cart").first():h(".composite_form").length?h(".composite_form"):0<e.closest("ul.products").length?e.closest("ul.products"):h(".cart:not(.in_loop)"))[0]||"function"!=typeof i[0].checkValidity||i[0].checkValidity()){var r,d,s,c=void 0===(s=0<e.closest("ul.products").length?(r="",(d=e.closest("li.product").find("a.add_to_cart_button")).data("product_id")):(r=e.closest(".product").find('input[name="add-to-cart"]'),d=e.closest(".product").find('input[name="product_id"]'),e.data("product_id")||(d.length?d.val():r.val())))?e.data("product_id"):s;(n=i.serializefiles()).append("context","frontend"),n.append("action","yith_ywraq_action"),n.append("ywraq_action","add_item"),n.append("product_id",e.data("product_id")),n.append("wp_nonce",e.data("wp_nonce")),n.append("yith-add-to-cart",e.data("product_id"));var _,l=a.find("input.qty").val();0<l&&n.append("quantity",l),0<h(".wc-product-table-wrapper").length&&0<(l=e.parents(".product-row").find(".cart input.qty").val())&&n.append("quantity",l),0<e.closest(".yith_wc_qof_button_and_price").length&&(_=e.closest(".yith_wc_qof_button_and_price").find(".YITH_WC_QOF_quantity_Cart").val(),n.append("quantity",_));var u=e.closest("li.product").find(".variations_form.in_loop"),y=!!u.length&&u.data("active_variation");return y&&(n.append("variation_id",y),u.find("select").each(function(){n.append(this.name,this.value)})),h(document).trigger("yith_ywraq_action_before"),!("undefined"!=typeof yith_wapo_general&&!yith_wapo_general.do_submit)&&(!("undefined"!=typeof ywcnp_raq&&!ywcnp_raq.do_submit)&&void(p=h.ajax({type:"POST",url:ywraq_frontend.ajaxurl.toString().replace("%%endpoint%%","yith_ywraq_action"),dataType:"json",data:n,contentType:!1,processData:!1,beforeSend:function(){e.after(' <img src="'+w+'" class="ywraq-loader" >')},complete:function(){e.next().remove()},success:function(t){"true"==t.result||"exists"==t.result?("yes"==ywraq_frontend.go_to_the_list?window.location.href=t.rqa_url:(h(".yith_ywraq_add_item_response-"+c).hide().addClass("hide").html(""),h(".yith_ywraq_add_item_product-response-"+c).show().removeClass("hide").html(t.message),h(".yith_ywraq_add_item_browse-list-"+c).show().removeClass("hide"),e.parent().hide().removeClass("show").addClass("addedd"),h(".add-to-quote-"+c).attr("data-variation",t.variations),f.length&&(f.ywraq_refresh_widget(),f=h(document).find(".widget_ywraq_list_quote, .widget_ywraq_mini_list_quote")),m()),h(document).trigger("yith_wwraq_added_successfully",[t])):"false"==t.result&&(h(".yith_ywraq_add_item_response-"+c).show().removeClass("hide").html(t.message),h(document).trigger("yith_wwraq_error_while_adding")),p=!1}})))}h('<input type="submit">').hide().appendTo(i).click().remove()}}),h.fn.serializefiles=function(){var t=h(this),n=new FormData;h.each(h(t).find("input[type='file']"),function(t,a){h.each(h(a)[0].files,function(t,e){n.append(a.name,e)})});var e=h(t).serializeArray(),a=!1;return h.each(e,function(t,e){"quantity"!=e.name&&!e.name.indexOf("quantity")||(a=!0),"add-to-cart"!=e.name&&n.append(e.name,encodeURIComponent(e.value))}),!1===a&&n.append("quantity",1),n},h.fn.ywraq_refresh_widget=function(){f.each(function(){var e=h(this),t=e.find(".yith-ywraq-list-wrapper"),a=e.find(".yith-ywraq-list"),n=e.find(".yith-ywraq-list-widget-wrapper").data("instance");h.ajax({type:"POST",url:ywraq_frontend.ajaxurl.toString().replace("%%endpoint%%","yith_ywraq_action"),data:n+"&ywraq_action=refresh_quote_list&action=yith_ywraq_action&context=frontend",beforeSend:function(){a.css("opacity",.5),e.hasClass("widget_ywraq_list_quote")&&t.prepend(' <img src="'+w+'" class="ywraq-loader">')},complete:function(){e.hasClass("widget_ywraq_list_quote")&&t.next().remove(),a.css("opacity",1)},success:function(t){e.hasClass("widget_ywraq_mini_list_quote")?e.find(".yith-ywraq-list-widget-wrapper").html(t.mini):e.find(".yith-ywraq-list-widget-wrapper").html(t.large),h(document).trigger("yith_ywraq_widget_refreshed")}})})},h(document).on("click",".yith-ywraq-item-remove",function(t){t.preventDefault();var e=h(this),o=e.data("remove-item"),a=e.parents(".ywraq-wrapper"),r=(h("#yith-ywraq-form"),a.find(".wpcf7-form")),d=a.find(".gform_wrapper"),s=e.data("product_id"),n="context=frontend&action=yith_ywraq_action&ywraq_action=remove_item&key="+e.data("remove-item")+"&wp_nonce="+e.data("wp_nonce")+"&product_id="+s;h.ajax({type:"POST",url:ywraq_frontend.ajaxurl.toString().replace("%%endpoint%%","yith_ywraq_action"),dataType:"json",data:n,beforeSend:function(){e.find(".ajax-loading").css("visibility","visible")},complete:function(){e.siblings(".ajax-loading").css("visibility","hidden")},success:function(t){var e,a,n,i;1===t?((e=h("[data-remove-item='"+o+"']").parents(".cart_item")).hasClass("composite-parent")&&(a=e.data("composite-id"),h("[data-composite-id='"+a+"']").remove()),e.hasClass("yith-wapo-parent")&&(n=e.find(".product-remove a").data("remove-item"),h("[data-wapo_parent_key='"+n+"']").remove()),e.hasClass("ywcp_component_item")&&h("tr.ywcp_component_child_item").filter("[data-wcpkey='"+o+"']").remove(),e.hasClass("bundle-parent")&&(i=e.data("bundle-key"),h("[data-bundle-key='"+i+"']").remove()),e.remove(),0===h(".cart_item").length&&(r.length&&r.remove(),d.length&&d.remove(),h("#yith-ywraq-form, .yith-ywraq-mail-form-wrapper").remove(),h("#yith-ywraq-message").html(ywraq_frontend.no_product_in_list)),f.length&&(f.ywraq_refresh_widget(),f=h(document).find(".widget_ywraq_list_quote, .widget_ywraq_mini_list_quote")),m(),h(document).find('.hide-when-removed[data-product_id="'+s+'"]').hide(),h(document).find('.yith-ywraq-add-button[data-product_id="'+s+'"]').show(),h(document).trigger("yith_wwraq_removed_successfully")):h(document).trigger("yith_wwraq_error_while_removing")}})}),h(".ywraq_clean_list").on("click",function(t){t.preventDefault(),h("#yith-ywrq-table-list tbody .product-remove a.remove").each(function(){h(this).trigger("click")})});var n;function m(){h(document).find(".ywraq_number_items").each(function(){var e=h(this),t=e.data("show_url"),a=e.data("item_name"),n=e.data("item_plural_name");h.ajax({type:"POST",url:ywraq_frontend.ajaxurl.toString().replace("%%endpoint%%","yith_ywraq_action"),data:"ywraq_action=refresh_number_items&action=yith_ywraq_action&context=frontend&item_name="+a+"&item_plural_name="+n+"&show_url="+t,success:function(t){e.replaceWith(t),h(document).trigger("ywraq_number_items_refreshed")}})})}0<h(".wpcf7-submit").closest(".wpcf7").length&&h(document).find(".ywraq-wrapper .wpcf7").each(function(){var t=h(this);t.find('input[name="_wpcf7"]').val()==ywraq_frontend.cform7_id&&(t.on("wpcf7:mailsent",function(){h.ajax({type:"POST",url:ywraq_frontend.ajaxurl.toString().replace("%%endpoint%%","yith_ywraq_order_action"),dataType:"json",data:{lang:ywraq_frontend.current_lang,action:"yith_ywraq_order_action",current_user_id:ywraq_frontend.current_user_id,context:"frontend",ywraq_order_action:"mail_sent_order_created"},success:function(t){""!=t.rqa_url&&(window.location.href=t.rqa_url)}})}),document.addEventListener("wpcf7mailsent",function(t){window.location.href=ywraq_frontend.rqa_url},!1))}),h("#yith-ywrq-table-list").on("change",".qty",function(){h(this).val()<=0&&h(this).val(1)}),h(document).bind("gform_confirmation_loaded",function(t,e){ywraq_frontend.gf_id==e&&(window.location.href=ywraq_frontend.rqa_url)}),ywraq_frontend.auto_update_cart_on_quantity_change&&h(document).on("click, change",".product-quantity input",function(t){var e,a,n,i,o=h(this),r=o.attr("name"),d=o.closest(".quantity");d.block(c),i=void 0===r?(r=(e=o.closest(".product-quantity").find(".input-text.qty")).attr("name"),a=e.val(),n=r.match(/[^[\]]+(?=])/g),o.hasClass("plus")&&a++,o.hasClass("minus")&&a--,"context=frontend&action=yith_ywraq_action&ywraq_action=update_item_quantity&quantity="+a+"&key="+n[0]):"context=frontend&action=yith_ywraq_action&ywraq_action=update_item_quantity&quantity="+(a=o.val())+"&key="+(n=r.match(/[^[\]]+(?=])/g))[0];h.ajax({type:"POST",url:ywraq_frontend.ajaxurl.toString().replace("%%endpoint%%","yith_ywraq_action"),dataType:"json",data:i,success:function(t){h.post(s,function(t){var e;""!=t&&(e=h("<div></div>").html(t).find("#yith-ywrq-table-list"),h("#yith-ywrq-table-list").html(e.html()),h(document).trigger("ywraq_table_reloaded"),f.length&&(f.ywraq_refresh_widget(),f=h(document).find(".widget_ywraq_list_quote, .widget_ywraq_mini_list_quote"))),d.unblock()})}})}),0<t.length&&1==ywraq_frontend.lock_shipping&&(t.find("input").attr("readonly","readonly"),t.find("select").attr("readonly","readonly"),h(".woocommerce-checkout #shipping_country_field").css("pointer-events","none"),h(".woocommerce-checkout #shipping_state_field").css("pointer-events","none")),0<e.length&&1==ywraq_frontend.lock_billing&&(e.find("input").attr("readonly","readonly"),e.find("select").attr("readonly","readonly"),h(".woocommerce-checkout #billing_country_field").css("pointer-events","none"),h(".woocommerce-checkout #billing_state_field").css("pointer-events","none")),f.ywraq_refresh_widget(),m(),h(document).on("click","#ywraq_checkout_quote",function(t){h(document).find('input[name="payment_method"]').val("yith-request-a-quote"),h("#ywraq_checkout_quote").val(!0)}),h(document).find(".theme-yith-proteo .ywraq-wrapper .woocommerce-message").removeAttr("role"),1==ywraq_frontend.enable_ajax_loading&&(n=function(){var t=h(document).find(".yith-ywraq-add-to-quote"),a=[];return 0!==t.length&&(h.each(t,function(){var t=h(this).closest(".variations_form "),e=h(this).find(".yith-ywraq-add-button").data("product_id");void 0===t&&a.push(e)}),a)}())&&function(t){var e={fragments:t,ywraq_action:"update_ywraq_fragments",action:"yith_ywraq_action",context:"frontend"};h.ajax({type:"POST",url:ywraq_frontend.ajaxurl.toString().replace("%%endpoint%%","yith_ywraq_action"),data:e,success:function(t){var n,e;"undefined"!=typeof t.error?console.log(t.error):!0===t.success&&(n=t.fragments,0<(e=h(document).find(".yith-ywraq-add-to-quote")).length&&h.each(e,function(){var t=h(this),e=t.data("variation"),a=t.find(".yith-ywraq-add-button").data("product_id");void 0===e&&"undefined"!=typeof n[a]&&t.replaceWith(n[a])}))}})}(n)});