!function(e,t){"use strict";var o=null,a=window.JetCWSettings,i=a.compareMaxItems,n=a.compareItemsCount,s={init:function(){var o={"jet-compare.default":s.compareWidget};e.each(o,function(e,o){t.hooks.addAction("frontend/element_ready/"+e,o)}),s.commonInit(),e(window).on("jet-popup/render-content/ajax/success",s.prepareJetPopup),e(window).on("jet-ajax-search/show-results/listing",function(e,t){s.bindHandlers(t)})},commonInit:function(){e(document).on("click.JetCW",'.jet-compare-button__link[href="#"]',s.addToCompare).on("click.JetCW",'.jet-wishlist-button__link[href="#"]',s.addToWishlist).on("click.JetCW",".jet-compare-item-remove-button",s.removeFromCompare).on("click.JetCW",".jet-wishlist-item-remove-button",s.removeFromWishlist).on("jet-cw-load",s.addLoader).on("jet-cw-loaded",s.removeLoader).on("jet-engine/listing-grid/after-lazy-load",s.prepareCWSettingsAfterAjaxLoad).on("jet-woo-builder-content-rendered",s.prepareCWSettingsAfterAjaxLoad),s.handleTableActions()},bindHandlers:function(e){e.find('.jet-compare-button__link[href="#"]').off("click.JetCW").on("click.JetCW",s.addToCompare),e.find('.jet-wishlist-button__link[href="#"]').off("click.JetCW").on("click.JetCW",s.addToWishlist)},prepareCWSettingsAfterAjaxLoad:function(e,t,o){s.setProperWidgetsSettings(o.data.jetCompareWishlistWidgets)},setProperWidgetsSettings:function(t){if(!t)return;let o={},i={},n=t.compare,s=t.wishlist;null===a.widgets?a.widgets={}:(o=a.widgets.compare,i=a.widgets.wishlist),a.widgets.compare=e.extend(o,n),a.widgets.wishlist=e.extend(i,s)},compareWidget:function(t){t.find(".jet-compare-table__wrapper").find(".jet-compare-table-action-control__clear").off(".JetCW").on("click.JetCW",function(t){t.stopImmediatePropagation(),s.removeFromCompare.call(e(this),t)})},handleTableActions:function(){e(document).on("click.JetCW",".jet-compare-table-action-control",function(t){const o=e(this),a=o.closest(".jet-compare-table__wrapper");if(!a.length)return;if(o.hasClass("jet-compare-table-action-control__clear"))return void s.removeFromCompare.call(o,t);t.preventDefault(),o.hasClass("jet-compare-table-action-control__highlight")&&a.toggleClass("jet-compare-table-highlight"),o.hasClass("jet-compare-table-action-control__differences")&&a.toggleClass("jet-compare-table-differences");const i=o.siblings(".jet-compare-table-action-control:not(.jet-compare-table-action-control__clear)");o.hasClass("active")?(o.removeClass("active"),i.removeClass("disable")):(o.addClass("active"),i.addClass("disable")),s.compareTableDifference(a)})},compareTableDifference:function(t){let o=t.find(".jet-compare-table-row"),a=t.hasClass("jet-compare-table-highlight"),i=t.hasClass("jet-compare-table-differences");o.each(function(){let t=e(this),o=t.find(".jet-compare-table-cell");if(s.exceptionsDifference(t))return;let n=[];o.each(function(){let t=e(this);if(-1!==n.indexOf(t.text().trim()))return!0;n.push(t.text().trim())}),a&&n.length>1?t.addClass("highlighted"):!a&&t.hasClass("highlighted")&&t.removeClass("highlighted"),i&&n.length<=1?t.hide():!i&&t.is(":hidden")&&t.show()})},exceptionsDifference:function(t){let o=!1;return e.each(["remove-button","add-to-cart","product-title","stock-status","thumbnail","price","rating-stars"],function(e,a){t.children().find(".jet-cw-"+a).length>0&&(o=!0)}),o},prepareJetPopup:function(e,t){let o=t.request.data;(o.isJetWooBuilder||o.isJetEngine)&&s.setProperWidgetsSettings(o.jetCompareWishlistWidgets)},removeFromCompare:function(t){t.preventDefault();var a=e(this),i=a.data("product-id");o&&o.abort(),e(document).trigger("jet-cw-load",[a,i,"jet_update_compare_list"]),o=s.ajaxRequest(a,"jet_update_compare_list","remove",i)},removeFromWishlist:function(t){t.preventDefault();var a=e(this),i=a.data("product-id");o&&o.abort(),e(document).trigger("jet-cw-load",[a,i,"jet_update_wish_list"]),o=s.ajaxRequest(a,"jet_update_wish_list","remove",i)},addToWishlist:function(t){t.preventDefault();var a=e(this),i=a.data("product-id");o&&o.abort(),e(document).trigger("jet-cw-load",[a,i,"jet_update_wish_list"]),a.hasClass("jet-wishlist-item-remove-button")||(o=s.ajaxRequest(a,"jet_update_wish_list","add",i))},addToCompare:function(t){if(t.preventDefault(),n>=i&&!e(this).hasClass("jet-compare-item-remove-button"))s.showMessages("compare_max_items");else{var a=e(this),r=a.data("product-id");o&&o.abort(),e(document).trigger("jet-cw-load",[a,r,"jet_update_compare_list"]),a.hasClass("jet-compare-item-remove-button")||(o=s.ajaxRequest(a,"jet_update_compare_list","add",r))}},ajaxRequest:function(t,o,i,r){e.ajax({url:a.ajaxurl,type:"POST",dataType:"json",data:{action:o,pid:r,context:i,widgets_data:a.widgets,nonce:a.nonce}}).done(function(a){a.success?("add"===i?("jet_update_wish_list"===o&&t.addClass("added-to-wishlist").closest(".jet-wishlist-button__container").addClass("added-to-wishlist"),"jet_update_compare_list"===o&&t.addClass("added-to-compare").closest(".jet-compare-button__container").addClass("added-to-compare")):"remove"===i&&t.removeClass("added-to-wishlist added-to-compare").closest(".jet-wishlist-button__container, .jet-compare-button__container").removeClass("added-to-wishlist added-to-compare"),n=a.data.compareItemsCount,s.renderResult(a.data),e(document).trigger("jet-cw-loaded",[t,r,o])):e(document).trigger("jet-cw-response-failed",[a])})},renderResult:function(t){let o=t.content;e.each(o,function(t,o){e(t).replaceWith(o),s.elementorFrontendInit(e(t)),s.compareWidget(e(t).offsetParent())})},addLoader:function(t,o,a,i){"jet_update_compare_list"===i&&(e('a.jet-compare-button__link[data-product-id="'+a+'"]').addClass("jet-cw-loading"),e("div.jet-compare-table__wrapper").addClass("jet-cw-loading"),e("a.jet-compare-count-button__link").addClass("jet-cw-loading")),"jet_update_wish_list"===i&&(e('a.jet-wishlist-button__link[data-product-id="'+a+'"]').addClass("jet-cw-loading"),e("a.jet-wishlist-count-button__link").addClass("jet-cw-loading"),e("div.jet-wishlist__content").addClass("jet-cw-loading"))},removeLoader:function(t,o,a,i){"jet_update_compare_list"===i&&(e('a.jet-compare-button__link[data-product-id="'+a+'"]').removeClass("jet-cw-loading"),e("div.jet-compare-table__wrapper").removeClass("jet-cw-loading"),e("a.jet-compare-count-button__link").removeClass("jet-cw-loading")),"jet_update_wish_list"===i&&(e('a.jet-wishlist-button__link[data-product-id="'+a+'"]').removeClass("jet-cw-loading"),e("a.jet-wishlist-count-button__link").removeClass("jet-cw-loading"),e("div.jet-wishlist__content").removeClass("jet-cw-loading"))},showMessages:function(t){var o=e(".jet-compare-message--max-items");"compare_max_items"===t&&(o.addClass("show"),setTimeout(function(){o.removeClass("show")},4e3))},elementorFrontendInit:function(t){t.find("[data-element_type]").each(function(){let t=e(this),o=t.data("element_type");o&&("widget"===o&&(o=t.data("widget_type"),window.elementorFrontend.hooks.doAction("frontend/element_ready/widget",t,e)),window.elementorFrontend.hooks.doAction("frontend/element_ready/global",t,e),window.elementorFrontend.hooks.doAction("frontend/element_ready/"+o,t,e))})}};t?e(window).on("elementor/frontend/init",s.init):s.commonInit()}(jQuery,window.elementorFrontend);