"use strict";window.Wolmart||(window.Wolmart={}),function(e){Wolmart.productCompare=function(){function o(e,o=!0){var a=e.html(),t=o?1:-1;a=a.replace(/[^0-9]/,""),(a=parseInt(a)+t)>=0&&a<=wolmart_vars.compare_limit&&e.html(a)}e(document).on("click",".product a.compare:not(.added)",(function(o){o.preventDefault();var a=e(this),t={action:"wolmart_add_to_compare",id:a.data("product_id"),minicompare:e(".header .compare-dropdown").length?e(".header .compare-dropdown").data("minicompare-type"):""};Wolmart.doLoading(a,"small"),e.ajax({type:"post",url:wolmart_vars.ajax_url,data:t,dataType:"json",success:function(o){Wolmart.endLoading(a),void 0!==o.count&&(e(".header .compare-dropdown .widget_compare_content").length&&e(".header .compare-dropdown .widget_compare_content").html(e(o.minicompare).find(".widget_compare_content").html()),e(document).trigger("added_to_compare",o.popup_template),a.addClass("added"),a.attr("href",o.url))}})})).on("click",".remove_from_compare",(function(a){a.preventDefault();var t=e(this),r={action:"wolmart_remove_from_compare",id:t.data("product_id")};Wolmart.doLoading(t,"small"),e.ajax({type:"post",url:wolmart_vars.ajax_url,data:r,dataType:"json",success:function(a){void 0!==a.count&&(Wolmart.endLoading(t),t.closest(".compare-popup").length?(t.closest("li").empty(),o(e(".compare-popup .compare-heading mark"),!1)):void 0!==a.compare_table&&t.closest(".wolmart-compare-table").replaceWith(a.compare_table),e(document).trigger("removed_from_compare",r.id))}})})).on("click",".compare-popup-overlay",(function(){e(".page-wrapper > .compare-popup").removeClass("show")})).on("click",".wolmart-compare-table .to-left, .wolmart-compare-table .to-right",(function(o){if(o.preventDefault(),!e(this).closest(".compare-basic-info").find(".d-loading").length){var a=e(this),t=a.closest(".compare-value").index()-1;a.closest(".compare-col").hasClass("last-col")&&a.hasClass("to-right")||e(this).closest(".wolmart-compare-table").find(".compare-row").each((function(){var o=e(this).children(".compare-value").eq(t),r=a.hasClass("to-left")?o.prev():o.next(),p=(a.hasClass("to-left")?"-":"")+"20%",c=(a.hasClass("to-left")?"":"-")+"20%";r.hasClass("compare-field")||(o.animate({left:p},200,(function(){o.css("left",""),a.hasClass("to-left")?o.after(r):o.before(r)})),r.animate({left:c},200,(function(){r.css("left","")})),setTimeout((function(){(r.hasClass("last-col")||o.hasClass("last-col"))&&(o.toggleClass("last-col"),r.toggleClass("last-col"))}),200))}))}})).on("click",".compare-clean",(function(o){o.preventDefault(),e(".remove_from_compare").each((function(){var o=e(this).data("product_id");e('.compare[data-product_id="'+o+'"]').removeClass("added")})),e(".compare-popup li").empty(),e(".compare-popup .compare-heading mark").text("0"),e.post(wolmart_vars.ajax_url,{action:"wolmart_clean_compare"}),e(".header .compare-open .compare-count").html("0")})).on("added_to_compare",(function(a,t){if(t)if("offcanvas"==wolmart_vars.compare_popup_type){var r=e(".page-wrapper > .compare-popup");r.length||(e(".page-wrapper").append('
'),r=e(".page-wrapper > .compare-popup")),r.html(t),Wolmart.slider(".compare-popup .slider-wrapper",{spaceBetween:10,slidesPerView:"auto",breakpoints:{992:{spaceBetween:30},768:{spaceBetween:20}},scrollbar:{el:".slider-scrollbar",dragClass:"slider-scrollbar-drag",draggable:!0}}),Wolmart.requestTimeout((function(){r.addClass("show")}),60)}else Wolmart.minipopup.open({content:t});if(e(".header .compare-open").length){var p=e(".header .compare-open").find(".compare-count");p.length&&o(p)}})).on("removed_from_compare",(function(a,t){if(e('.compare[data-product_id="'+t+'"]').removeClass("added"),e(".header .compare-open").length){var r=e(".header .compare-open").find(".compare-count"),p=e(".header .compare-dropdown");r.length&&o(r,!1),p.find(".mini-item").length>1?p.find('.remove_from_compare[data-product_id="'+t+'"]').closest(".mini-item").remove():p.find(".widget_compare_content").html(e("script.wolmart-minicompare-no-item-html").html())}})).on("click",".compare-offcanvas .compare-open",(function(o){e(this).closest(".compare-dropdown").toggleClass("opened"),o.preventDefault()})).on("click",".compare-offcanvas .btn-close",(function(o){o.preventDefault(),e(this).closest(".compare-dropdown").removeClass("opened")})).on("click",".compare-offcanvas .compare-overlay",(function(o){e(this).closest(".compare-dropdown").removeClass("opened")}))},e(window).on("wolmart_complete",Wolmart.productCompare)}(jQuery);