!function(T){"use strict";etTheme.autoinit.XStoreCompare=etTheme.XStoreCompare=function(){var m,p,o,u,s,c,d,l,_,t,f,a;function h(r,i,n){r<i?T(n[r]).hasClass("processing")||(T(n[r]).trigger("click").addClass("processing"),T(document.body).on("added_to_cart",function(e,t,o,a){a.attr("data-product_id")==T(n[r]).attr("data-product_id")&&(a.removeClass("processing in-process"),h(++r,i,n))})):T(n[r-1]).parent().hasClass("keeper-all-products-buttons")&&T(".et_b_header-compare").find("li").unblock()}function g(e,t,o){e<t&&(T(o[e]).hasClass("processing")||T(o[e]).trigger("click",{is_multiple:!0,i:e,max:t,buttons:o}).addClass("processing"))}function x(e,t,o){var a;e<t&&(a=_?"in-process":"processing",T(o[e]).hasClass(a)||T(o[e]).trigger("click",{is_multiple:!0,i:e,max:t,buttons:o}).addClass(a))}function v(){var e;return o||(T.ajax({url:xstore_compare_params.ajaxurl,dataType:"json",method:"POST",data:{cookie_key:p,action:"xstore_get_user_compare"},success:function(e){return o=e.products.products.map(e=>JSON.stringify(e))},error:function(){},complete:function(){}}),(e=etTheme.getCookie(p))?e.split("|"):[])}function b(){var e;return o?o.map(e=>JSON.parse(e).id):(T.ajax({url:xstore_compare_params.ajaxurl,dataType:"json",method:"POST",data:{cookie_key:p,action:"xstore_get_user_compare"},success:function(e){var t=e.products.products;return o=e.products.products.map(e=>JSON.stringify(e)),t},error:function(){},complete:function(){}}),(e=etTheme.getCookie(p))&&T.isArray(e)?e.split("|").map(e=>JSON.parse(e).id):[])}function y(e,o={}){e=parseInt(e);var a=v(),t=a.map(e=>JSON.parse(e).id).indexOf(e);if(-1<t){if(a.splice(t,1),etTheme.setCookie(p,a.join("|")),o.table_row)o.table_row.css({position:"relative",zoom:1}),o.table_row.find("td:last-child").block({message:null,overlayCSS:{opacity:.6}}).attr("style",null),_?setTimeout(function(){o.table_row.remove()},1500):(o.table_row.find("td:last-child").unblock(),setTimeout(function(){o.table_row.attr("style",null)},500));else if(o.table_cols&&_){let t=o.table_cols.first().parents(".xstore-compare-table");t.block({message:null,overlayCSS:{opacity:.6}}),setTimeout(function(){a.length<4?o.table_cols.each(function(){T(this).attr("data-product_id","ghost-product-"+(4-a.length)),T(this).hasClass("xstore-compare-product")?T(this).html('<span class="xstore-compare-image">'+xstore_compare_params.placeholder_image+"</span>"):T(this).html(""),T(this).parent().append(T(this).remove())}):o.table_cols.each(function(){T(this).remove()})}),setTimeout(function(){t.unblock().removeClass("processing").attr("style",null);var e=t.parent();r(e,"horizontal")||e.find(".xstore-compare-table-arrow").remove()},500)}T(document).find("."+m+"[data-id="+e+"]").each(function(){o.table_row||T(this).addClass("processing"),f(T(this),JSON.parse(T(this).attr("data-settings")),"remove")}),!o.minicompare||o.liItem.parents(".etheme-elementor-off-canvas").length||o.liItem.block({message:null,overlayCSS:{opacity:.6}}),xstore_compare_params.is_loggedin&&(clearTimeout(u),u=setTimeout(function(){k(a.join("|"))},1500)),o.is_multiple?(o.i++,T(document).trigger("xstore_compare/removing_product",[a,e,o.is_multiple,o.i,o.max,o.buttons])):T(document).trigger("xstore_compare/removing_product",[a,e])}}function r(e,t){return"vertical"==t?e.get(0).scrollHeight>e.innerHeight():"horizontal"==t&&e.get(0).scrollWidth>e.innerWidth()}function k(e){T.ajax({url:xstore_compare_params.ajaxurl,dataType:"json",method:"POST",data:{action:"xstore_update_user_compare",cookie_key:p,products:e},success:function(e){},error:function(){},complete:function(){}})}function i(e,t){e.length&&(t?(e.attr("data-o_id")||e.attr("data-o_id",e.data("id")),e.attr("data-id",t)):void 0!==e.attr("data-o_id")&&e.attr("data-id",e.attr("data-o_id")),a(e,parseInt(t)))}function n(e){void 0!==e.attr("data-o_id")&&(e.attr("data-id",e.attr("data-o_id")),a(e,e.attr("data-o_id")))}"undefined"!=typeof Cookies&&(etTheme.xstore_compare={},m="xstore-compare",p=xstore_compare_params.compare_id,o=null,c=s=u=0,d=etTheme.et_global.w_width<etTheme.et_global.mob_header_start||etConfig.layoutSettings.is_mobile?T(".mobile-header-wrapper"):T(".header-wrapper"),l=T("body").hasClass("xstore-compare-page"),_=T("body").hasClass("xstore-compare-owner"),t=0,xstore_compare_params.ajax_fragments&&(T(document).on("xstore_compare_initialized",function(e,t){T(document).trigger("xstore_compare_fragment_refresh",[t])}),T(window).on("pageshow",function(e){e.originalEvent.persisted&&(T(".et_b_compare-dropdown").empty(),T(document).trigger("xstore_compare_fragment_refresh",[v()]))}),T(document).on("xstore_compare_force_fragment_refresh",function(){T(".et_b_compare-dropdown").empty(),T(document).trigger("xstore_compare_fragment_refresh",[v()])})),T(document).on("click","."+m,function(e,t){e.preventDefault();var o=T(this).attr("data-action"),a=T(this).attr("data-id"),r=T(this).data("settings")||{},i=T(this).hasClass(m+"-redirect"),e=t&&!!t.is_multiple,n={},s=(e&&(n={is_multiple:!0,i:t.i,max:t.max,buttons:t.buttons}),T(this).parents("td"));switch((e||s)&&(n.table_cols=T(this).parents("table").find('td[data-product_id="'+a+'"]')),o){case"add":T(this).addClass("processing"),f(T(this),r,o);var c,[d,l={}]=[a,n];d=parseInt(d),-1===b().indexOf(d)&&((c=v()).push(JSON.stringify({id:d,time:Math.floor((new Date).getTime()/1e3)})),etTheme.setCookie(p,c.join("|"),xstore_compare_params.days_cache),l.table_row&&!_&&(l.table_row.css({position:"relative",zoom:1}),l.table_row.find("td:last-child").block({message:null,overlayCSS:{opacity:.6}}).attr("style",null),l.table_row.find("td:last-child").unblock(),setTimeout(function(){l.table_row.attr("style",null)},500)),xstore_compare_params.is_loggedin&&(clearTimeout(u),u=setTimeout(function(){k(c.join("|"))},1500)),T(document).find("."+m+"[data-id="+d+"]").each(function(){T(this).addClass("processing"),f(T(this),JSON.parse(T(this).attr("data-settings")))}),l.is_multiple?(l.i++,T(document).trigger("xstore_compare/adding_product",[c,d,l.is_multiple,l.i,l.max,l.buttons])):T(document).trigger("xstore_compare/adding_product",[c,d])),i&&T(this).addClass(m+"-redirect-ready");break;case"remove":i&&T(this).hasClass(m+"-redirect-ready")?window.location.href=xstore_compare_params.compare_page_url:(_||s||T(this).addClass("processing"),f(T(this),r,o),y(a,n))}}),f=function(e,t,o="add"){"add"==o?(t.removeText&&(e.find(".button-text").text(t.removeText),e.find(".mt-mes").text(t.removeText)),t.iconRemove&&t.iconRemove!=t.iconAdd&&e.find(".et-icon").addClass(t.iconRemove).removeClass(t.iconAdd),e.attr("data-action","remove"),e.attr("href",e.attr("href").replace("add_to_compare","remove_compare"))):(t.addText&&(e.find(".button-text").text(t.addText),e.find(".mt-mes").text(t.addText)),t.iconAdd&&t.iconAdd!=t.iconRemove&&e.find(".et-icon").addClass(t.iconAdd).removeClass(t.iconRemove),e.attr("data-action","add"),e.attr("href",e.attr("href").replace("remove_compare","add_to_compare"))),e.removeClass(m+"-redirect-ready"),setTimeout(function(){e.removeClass("processing"),e.removeClass("in-process")},300)},T(document).on("click",".xstore-minicompare-remove",function(e){e.preventDefault(),y(T(this).data("id"),{minicompare:!0,liItem:T(this).parents("li")})}),T(".xstore-compare-table :checkbox").on("click",function(){var e;"product-bulk-select"==T(this).attr("name")?T(this).closest("table").children("tbody").find(":checkbox").prop("checked",T(this).prop("checked")):(e=T(this).closest("tbody").find(':checkbox:not([name="product-bulk-select"])').filter(":visible:enabled").not(":checked"),T(this).closest("table").find(':checkbox[name="product-bulk-select"]').prop("checked",function(){return 0===e.length}))}),T(document).on("click",".xstore-compare-form .add-all-products",function(e){e.preventDefault(),confirm(xstore_compare_params.confirmQuestion)&&(etConfig.ajaxProductAddedNotify.type="alert",(e=T(this).closest(".xstore-compare-form").find("table").children("tbody").find(":checkbox").parents("tr").find(".ajax_add_to_cart")).length<1?alert(xstore_compare_params.no_products_available):h(0,e.length,e))}),T(document).on("click",".et_b_header-compare .add-all-products",function(e){var t;e.preventDefault(),confirm(xstore_compare_params.confirmQuestion)&&(etConfig.ajaxProductAddedNotify.type="alert",(t=(e=T(this).parents(".et_b_header-compare")).find(".keeper-all-products-buttons .ajax_add_to_cart")).length?(e.find("li").block({message:null,overlayCSS:{opacity:.6}}),h(0,t.length,t)):t.length<1&&alert(xstore_compare_params.no_products_available))}),T(".xstore-compare-actions").on("click",function(e){e.preventDefault();var o,t,a=!(etConfig.ajaxProductAddedNotify.type="alert"),r=!1,e=T(this).closest(".xstore-compare-form").find("table").children("tbody").find(":checkbox:checked"),r=[];if(e.parents("td").each(function(){var e=T(this).data("product_id");r.push(T(this).closest(".xstore-compare-form").find("table").children("tbody").find('td[data-product_id="'+e+'"]'))}),r.length<1)alert(xstore_compare_params.no_active_checkbox);else if(confirm(xstore_compare_params.confirmQuestion))switch(T(this).parent().find("select").val()){case"add":a?o=a.find(".ajax_add_to_cart"):r&&(o=[],r.forEach(function(e,t){e=T(e).find(".ajax_add_to_cart");e.length&&o.push(e)})),o.length<1?alert(xstore_compare_params.no_products_available):h(0,o.length,o);break;case"add_compare":a?o=a.find("."+m+'[data-action="add"]'):r&&(o=[],r.forEach(function(e,t){e=T(e).find("."+m+'[data-action="add"]');e.length&&o.push(e)})),o.addClass("in-process"),g(0,o.length,o);break;case"remove":a?o=a.find("."+m+'[data-action="remove"]"]'):r&&(o=[],r.forEach(function(e,t){e=T(e).find("."+m+'[data-action="remove"]');e.length&&o.push(e)})),_?(t=T(this).closest(".xstore-compare-form").find("table").children("tbody").find("td."+m+"-action[data-product_id]"),o.length==t.find("."+m).length?(etTheme.setCookie(p,"",0),xstore_compare_params.is_loggedin&&k([]),T(document).trigger("xstore_compare_fragment_refresh",[[]])):x(0,o.length,o)):(o.addClass("in-process"),x(0,o.length,o))}}),etTheme.xstore_compare.force_init_active_compare=function(){T.ajax({url:xstore_compare_params.ajaxurl,dataType:"json",method:"POST",data:{cookie_key:p,action:"xstore_get_user_compare"},success:function(e){o=e.products.products.map(e=>JSON.stringify(e)),T(document).trigger("xstore_compare_initialized",[o])},error:function(){},complete:function(){}})},l&&T(".xstore-compare-table-wrapper").length&&(r(T(".xstore-compare-table-wrapper"),"horizontal")||T(".xstore-compare-table-wrapper").find(".xstore-compare-table-arrow").remove()),T(".xstore-compare-table-arrow").on("click",function(){var e,t,o;e=T(this),t=e.parent(),o=e.parent().find("tbody").find("tr:last-child td:last-child").outerWidth(),"right"==e.data("side")?(e=o+t.scrollLeft(),t.animate({scrollLeft:e})):(e=o-t.scrollLeft(),t.animate({scrollLeft:-e}))}),T(document).on("xstore_compare/removing_product",function(e,t,o,a,r,i,n){if(a&&r<i)setTimeout(function(){x(r,i,n)},1700);else{if(clearTimeout(c),c=setTimeout(function(){T(document).trigger("xstore_compare_fragment_refresh",[t])},700),l&&void 0!==etTheme.quickView&&T(e.target.activeElement).parents(".et-quick-view-wrapper").length)etTheme.et_woocommerce.quick_view_opened&&etTheme.closeQuickView();T(document).trigger("xstore_compare/removed_product")}}),T(document).on("xstore_compare/adding_product",function(e,a,r,t,o,i,n){if(t&&o<i)setTimeout(function(){g(o,i,n)},1700);else switch(clearTimeout(c),c=setTimeout(function(){T(document).trigger("xstore_compare_fragment_refresh",[a])},700),clearTimeout(s),T(document).trigger("xstore_compare/added_product"),xstore_compare_params.notify_type){case"alert":etTheme.notify(etConfig.successfullyAdded);break;case"alert_advanced":T.ajax({url:xstore_compare_params.ajaxurl,data:{product_id:r,action:"xstore_get_compare_product_info"},method:"POST",success:function(e){var t=T("<a>",{class:"et-notify-image",href:e.product_link,target:"_self"}).html(e.product_image),e=T("<div>",{class:"et-notify-info"}).html(e.product_title),o=T("<a>",{class:"et-notify-button",href:xstore_compare_params.compare_page_url}).html(xstore_compare_params.view_compare);e.append(o[0].outerHTML),etTheme.notify(t[0].outerHTML+e[0].outerHTML,"info",5e3,!0)}});break;case"mini_compare":let e=T(d).find(".et_b_header-compare.et_element-top-level"),t=T(d).find(".et_b_header-compare.et_element-top-level.et-off-canvas .et-mini-content"),o=T(d).find(".et_b_header-compare.et_element-top-level.et-off-canvas");o.length&&(etTheme.closeQuickView(),etTheme.showHideElementsOnCanvasActions(!0),etTheme.et_global.deny_link_click=!0,T(".et-mobile-panel-wrapper").addClass("outside")),e.addClass("active"),t.addClass("active"),o.addClass("et-content-shown"),s=setTimeout(function(){e.removeClass("active")},1e3)}}),T(document).on("found_variation","form.variations_form",function(e,t){var o=T(e.target).closest(".product").find(".xstore-compare-single");o.length&&(xstore_compare_params.is_multilingual?(o.block({message:null,overlayCSS:{opacity:.6}}),T.ajax({url:xstore_compare_params.ajaxurl,data:{variation_id:t.variation_id,action:"xstore_get_origin_compare_product_variation_id"},method:"POST",success:function(e){i(o,e.variation_id),o.unblock()}})):i(o,t.variation_id))}),T(document).on("reset_data","form.variations_form",function(e){e=T(e.target).closest(".product").find(".xstore-compare-single");e.length&&n(e)}),T(document).on("found_variation","div.st-swatch-in-loop",function(e,t){var o=T(e.target).closest(".product").find(".xstore-compare");o.length&&(xstore_compare_params.is_multilingual?(o.block({message:null,overlayCSS:{opacity:.6}}),T.ajax({url:xstore_compare_params.ajaxurl,data:{variation_id:t.variation_id,action:"xstore_get_origin_compare_product_variation_id"},method:"POST",success:function(e){i(o,e.variation_id),o.unblock()}})):i(o,t.variation_id))}),T(document).on("reset_data","div.st-swatch-in-loop",function(e){e=T(e.target).closest(".product").find(".xstore-compare");e.length&&n(e)}),T(document).on("change",".xstore-compare-form .xstore-compare-quantity .qty",function(){if(clearTimeout(t),0==T(this).val()){let e=T(this).parents("tbody").find('td[data-product_id="'+T(this).parents("td").data("product_id")+'"] .'+m+'[data-action="remove"]');t=setTimeout(function(){e.trigger("click")},1500)}}),a=etTheme.xstore_compare.switch_variation_button=function(e,t){-1===b().indexOf(t)?f(e,JSON.parse(e.attr("data-settings")),"remove"):f(e,JSON.parse(e.attr("data-settings")))},etTheme.xstore_compare.force_init_active_compare(),T(document).on("xstore_compare_fragment_refresh",function(e,t){var o;o=t,T.ajax({url:xstore_compare_params.ajaxurl,data:{products:o,products_count:o.length,action:"xstore_compare_fragments"},method:"POST",success:function(e){e&&e.fragments&&T.each(e.fragments,function(e,t){T(e).replaceWith(t)}),o.length<1?(T(".et_b_header-compare").find(".product_list-popup-footer-wrapper").hide(),_&&l&&T.ajax({url:xstore_compare_params.ajaxurl,data:{action:"xstore_empty_compare_page"},method:"POST",success:function(e){e&&e.page_content&&(T(document).find("form.xstore-compare-form").replaceWith(e.page_content),T(document).find(".xstore-compare-share").remove())}})):T(".et_b_header-compare").find(".product_list-popup-footer-wrapper").attr("style",null),T(document).trigger("xstore_compare_fragment_refreshed",[o])}})}))}}(jQuery);