(function(n){var i=function(t){return t.is(".processing")||t.parents(".processing").length};var r=function(t){if(!n.fn.block||!t){return}if(!i(t)){t.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}};var a=function(t){if(!n.fn.unblock||!t){return}t.removeClass("processing").unblock()};var d=function(t,i){this.options=n.extend({duration:3e3,type:"notice"},i);this.$notice=null;this.$wrapper=n("#wcboost-flyout-notices-container");if(!this.$wrapper.length){this.$wrapper=n('<div id="wcboost-flyout-notices-container" class="wcboost-flyout-notices-container" />').appendTo(document.body)}this.$notice=n('<div class="wcboost-flyout-notice wcboost-notice" role="alert"/>').addClass("wcboost-notice--"+this.options.type).append(n(t));this.wait=null;this.show=this.show.bind(this);this.hide=this.hide.bind(this);this.delayHide=this.delayHide.bind(this);this.resetDelayHide=this.resetDelayHide.bind(this);if(this.options.duration>0){this.$notice.on("mouseenter",this.resetDelayHide).on("mouseleave",this.delayHide)}};d.prototype.show=function(){if(!this.$notice){return}this.$notice.hide();this.$wrapper.append(this.$notice);this.$notice.fadeIn();if(this.options.duration>0){this.delayHide()}};d.prototype.delayHide=function(){this.resetDelayHide();this.wait=setTimeout(this.hide,this.options.duration)};d.prototype.hide=function(){this.$notice.fadeOut()};d.prototype.resetDelayHide=function(){clearTimeout(this.wait)};var t=function(){this.selectors={text:".wcboost-wishlist-button__text",icon:".wcboost-wishlist-button__icon"};this.addToWishlist=this.addToWishlist.bind(this);this.removeFromWishlist=this.removeFromWishlist.bind(this);this.updateButton=this.updateButton.bind(this);n(document.body).on("click",".wcboost-wishlist-button--ajax",{addToWishlistHandler:this},this.onButtonClick);if("yes"===wcboost_wishlist_params.allow_adding_variations){n(".variations_form").on("found_variation",{addToWishlistHandler:this},this.onVariationFound).on("reset_data",{addToWishlistHandler:this},this.onVariationReset)}};t.prototype.onButtonClick=function(t){var i=t.data.addToWishlistHandler;var e=n(t.currentTarget);if(!e.hasClass("added")){t.preventDefault();i.addToWishlist(e)}else if("remove"===wcboost_wishlist_params.exists_item_behavior){t.preventDefault();i.removeFromWishlist(e)}};t.prototype.addToWishlist=function(o){var s=this;var t={product_id:o.data("product_id"),quantity:o.data("quantity")};if(!t.product_id){return}n.post({url:woocommerce_params.wc_ajax_url.toString().replace("%%endpoint%%","add_to_wishlist"),data:t,dataType:"json",beforeSend:function(){o.removeClass("added").addClass("loading");s.updateButton(o,"loading")},success:function(t){if(!t.success){if(t.data.redirect_url){location.href=t.data.redirect_url}else if(t.data.message){var i=new d(t.data.message);i.show()}s.updateButton(o,"removed");return}var e=t.data.fragments;s.updateButton(o,"added",t.data);n(document.body).trigger("added_to_wishlist",[o,e]).trigger("wishlist_item_added",[t.data]);if("yes"===wcboost_wishlist_params.wishlist_redirect_after_add){window.location=wcboost_wishlist_params.wishlist_url}},complete:function(){o.removeClass("loading")}})};t.prototype.removeFromWishlist=function(e){var o=this;var t=new URLSearchParams(e[0].search);var i={item_key:t.get("remove-wishlist-item"),_wpnonce:t.get("_wpnonce")};if(!i.item_key){return}n.post({url:woocommerce_params.wc_ajax_url.toString().replace("%%endpoint%%","remove_wishlist_item"),data:i,dataType:"json",beforeSend:function(){e.removeClass("added").addClass("loading");o.updateButton(e,"loading")},success:function(t){if(!t.success){return}var i=t.data.fragments;o.updateButton(e,"removed",t.data);n(document.body).trigger("removed_from_wishlist",[e,i]).trigger("wishlist_item_removed",[t.data])},complete:function(){e.removeClass("loading")}})};t.prototype.onVariationFound=function(t,i){var e=t.data.addToWishlistHandler;var o=n(t.target).closest(".product").find(".wcboost-wishlist-button");var s=o.data("variations");e.updateButton(o,"update_id",{product_id:i.variation_id});if("yes"===wcboost_wishlist_params.allow_adding_variations&&s){var r=s.find(function(t){return t.variation_id===i.variation_id});if(r){e.updateButton(o,r.added==="yes"?"added":"removed",r)}}};t.prototype.onVariationReset=function(t){var i=t.data.addToWishlistHandler;var e=n(t.target).closest(".product").find(".wcboost-wishlist-button");var o=e.data("variations");var s=null;i.updateButton(e,"update_id",{product_id:null});if(o){var r=o.find(function(t){return t.is_parent});if(r){s=r.variation_id}if("yes"===wcboost_wishlist_params.allow_adding_variations&&r){i.updateButton(e,r.added==="yes"?"added":"removed",r)}}if(!s){var a=new URLSearchParams(e[0].search);s=a.get("add-to-wishlist")}i.updateButton(e,"update_id",{product_id:s})};t.prototype.updateButton=function(t,i,e){switch(i){case"loading":t.addClass("loading");t.find(this.selectors.icon).html(wcboost_wishlist_params.icon_loading);break;case"added":t.removeClass("loading").addClass("added");switch(wcboost_wishlist_params.exists_item_behavior){case"view_wishlist":t.attr("href",e.wishlist_url?e.wishlist_url:wcboost_wishlist_params.wishlist_url);t.find(this.selectors.text).text(wcboost_wishlist_params.i18n_view_wishlist);t.find(this.selectors.icon).html(wcboost_wishlist_params.icon_filled);break;case"remove":t.attr("href",e.remove_url);t.find(this.selectors.text).text(wcboost_wishlist_params.i18n_remove_from_wishlist);t.find(this.selectors.icon).html(wcboost_wishlist_params.icon_filled);break;case"hide":t.hide();break}break;case"removed":t.removeClass("added loading");t.find(this.selectors.text).text(wcboost_wishlist_params.i18n_add_to_wishlist);t.find(this.selectors.icon).html(wcboost_wishlist_params.icon_normal);if(e&&e.add_url){t.attr("href",e.add_url)}break;case"update_id":t.data("product_id",e.product_id).attr("data-product_id",e.product_id);break}};var e=function(t){var i=this;i.$form=t;i.$wrapper=t.closest(".wcboost-wishlist");i.updateForm=i.updateForm.bind(i);i.showNotices=i.showNotices.bind(i);i.$wrapper.off(".wcboost-wishlist");i.$wrapper.on("click.wcboost-wishlist",".wcboost-wishlist-form .product-remove > a",{wishlist:i},i.onRemoveItem);i.$wrapper.on("click.wcboost-wishlist","a.restore-item",{wishlist:i},i.onRestoreItem);i.$wrapper.on("change.wcboost-wishlist input.wcboost-wishlist",":input",{wishlist:i},i.onInputChagne);i.$wrapper.on("submit.wcboost-wishlist","form",{wishlist:i},i.onSubmitForm);i.$form.find('button[name="update_wishlist"]').prop("disabled",true).attr("aria-disabled",true)};e.prototype.onRemoveItem=function(t){t.preventDefault();var i=t.data.wishlist;n.ajax({url:t.currentTarget.href,type:"GET",dataType:"html",beforeSend:function(){r(i.$form)},success:function(t){i.updateForm(t)},complete:function(){if(i.$form){a(i.$form)}var t=n('[role="alert"]');if(t.length){n("html, body").animate({scrollTop:t.offset().top-100},1e3)}}})};e.prototype.onRestoreItem=function(t){t.preventDefault();var i=t.data.wishlist,e=i.$form?i.$form:i.$wrapper;n.ajax({url:t.currentTarget.href,type:"GET",dataType:"html",beforeSend:function(){r(e)},success:function(t){i.updateForm(t)},complete:function(){a(e)}})};e.prototype.onInputChagne=function(t){var i=t.data.wishlist;i.$form.find('button[name="update_wishlist"]').prop("disabled",false).attr("aria-disabled",false)};e.prototype.onSubmitForm=function(t){t.preventDefault();var i=t.data.wishlist;n("<input />").attr("type","hidden").attr("name","update_wishlist").attr("value","Update Wishlist").appendTo(i.$form);n.ajax({type:i.$form.attr("method"),url:i.$form.attr("action"),data:i.$form.serialize(),dataType:"html",beforeSend:function(){r(i.$form)},success:function(t){i.updateForm(t)},complete:function(){if(i.$form){a(i.$form)}}})};e.prototype.updateForm=function(t){var i=this,e=n.parseHTML(t),o=n(".wcboost-wishlist-form",e),s=n(".woocommerce-error, .woocommerce-message, .woocommerce-info, .is-info, .is-success, .is-error",e);n(".woocommerce-error, .woocommerce-message, .woocommerce-info, .is-info, .is-success, .is-error").remove();if(!o.length){var r=n(".wishlist-empty",e).closest(".wcboost-wishlist");r.find(".woocommerce-error, .woocommerce-message, .woocommerce-info, .is-info, .is-success, .is-error").not(".wishlist-empty").remove();i.$wrapper.html(r.html());i.$form=null;s=s.not(".wishlist-empty");n(document.body).trigger("wishlist_emptied",[i])}else{if(i.$form){i.$form.replaceWith(o);i.$form=o}else{var a=o.closest(".wcboost-wishlist");i.$wrapper.html(a.html());i.$form=i.$wrapper.find(".wcboost-wishlist-form")}i.$form.find('button[name="update_wishlist"]').prop("disabled",true).attr("aria-disabled",true)}if(s&&s.length>0){i.showNotices(s)}n(document.body).trigger("wishlist_updated",[i])};e.prototype.showNotices=function(t,i){if(i){i.prepend(t)}else{this.$wrapper.prepend(t)}};var o=function(){var t=this;t.openSocialShareIframe=t.openSocialShareIframe.bind(t);t.showCopiedNotice=t.showCopiedNotice.bind(t);t.showWishlistURLNotice=t.showWishlistURLNotice.bind(t);n(document.body).on("click.wcboost-wishlist",".wcboost-wishlist-share-link",{wishlistShareHandler:t},t.onClickShareLink)};o.prototype.onClickShareLink=function(t){var i=t.data.wishlistShareHandler,e=t.currentTarget.href,o=t.currentTarget.dataset.social;if("email"===o){return}if("link"===o){t.preventDefault();try{navigator.clipboard.writeText(e).then(i.showCopiedNotice)}catch(t){i.showWishlistURLNotice(e)}}else{var s=i.openSocialShareIframe(e);if(s){t.preventDefault()}}};o.prototype.openSocialShareIframe=function(t){var i=500,e=450,o=window.screen.height/2-(e/2+50),s=window.screen.width/2-(i/2+10),r="status=no,resizable=yes,width="+i+",height="+e+",left="+s+",top="+o+",screenX="+s+",screenY="+o+",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";if(window.screen.width<=i){return false}var a=window.open(t,"sharer",r);a.focus();return true};o.prototype.showCopiedNotice=function(){if(!this.copiedNotice){this.copiedNotice=new d(n('<div class="wcboost-wishlist-link-copied-notice wcboost-wishlist-share-notice" />').text(wcboost_wishlist_params.i18n_link_copied_notice),{type:"message"})}this.copiedNotice.show()};o.prototype.showWishlistURLNotice=function(t){if(!this.urlNotice){var i=n('<div class="wcboost-wishlist-share-notice" />');i.append('<input type="text" value="" />');i.append('<span class="wcboost-wishlist-share-notice__close" role="button">'+wcboost_wishlist_params.i18n_close_button_text+"</span>");var e=new d(i,{duration:-1,type:"info"});i.on("click",".wcboost-wishlist-share-notice__close",function(){e.hide()});this.urlNotice=e}this.urlNotice.show();this.urlNotice.$notice.find("input").val(t).focus()};var s=function(){var t=this;t.selectors={widget:".wcboost-wishlist-widget",content:".wcboost-wishlist-widget-content"};t.checkWidgetVisibility=t.checkWidgetVisibility.bind(t);n(document.body).on("click",t.selectors.content+" a.remove",{wishlistWidget:t},t.removeItem).on("wishlist_fragments_loaded",{wishlistWidget:t},t.checkWidgetVisibility);t.checkWidgetVisibility()};s.prototype.checkWidgetVisibility=function(){var t=this;var i=n(t.selectors.widget);if(!i.length){return}i.each(function(){var t=n(this);if(!t.find(".wcboost-wishlist-widget__hide-if-empty").length){return}if(t.find(".wcboost-wishlist-widget__products").length){t.show()}else{t.hide()}})};s.prototype.removeItem=function(t){t.preventDefault();var i=t.data.wishlistWidget;var e=new URLSearchParams(t.currentTarget.search);var o={item_key:e.get("remove-wishlist-item"),_wpnonce:e.get("_wpnonce")};if(!o.item_key){return}var s=n(i.selectors.widget);n.post({url:woocommerce_params.wc_ajax_url.toString().replace("%%endpoint%%","remove_wishlist_item"),data:o,dataType:"json",beforeSend:function(){r(s)},success:function(t){if(!t.success){return}var i=t.data.fragments;n(document.body).trigger("removed_from_wishlist",[null,i])},complete:function(){a(s)}})};n(function(){new t;new e(n(".wcboost-wishlist-form"));new o;new s})})(jQuery);