window.Wolmart||(window.Wolmart={}),function(a){var e={action:"wolmart_get_comments",post_id:null,mode:"all",page:1,$tabs:null,$pagination:null,$panel:null,$activePanel:null,cache:{},init:function(){this.$tabs=a(".woocommerce-Reviews .nav-tabs"),this.$pagination=a(".woocommerce-Reviews .pagination"),this.post_id=this.$tabs.data("post_id"),a("body").on("click",".woocommerce-Reviews .nav-link",this.filterComments).on("click",".woocommerce-Reviews .woocommerce-pagination .page-numbers",this.changePage).on("click",".review-vote .comment_help, .review-vote .comment_unhelp",this.onVoteComment)},filterComments:function(t){var n=a(this);if(!e.$tabs.hasClass("loading")){var o="SPAN"==this.tagName?n.data("href"):n.attr("href");e.$panel="#"==o?n.closest(".nav").siblings(".tab-content").children(".tab-pane").eq(n.parent().index()):a(("#"==o.substring(0,1)?"":"#")+o),e.$panel.length&&(t.preventDefault(),e.$activePanel=e.$panel.parent().children(".active"),!n.hasClass("active")&&o&&(e.$tabs.find(".active").removeClass("active"),n.addClass("active"),e.mode=n.data("mode"),e.page=1,e.getComments()))}},changePage:function(t){var n=a(this),o=n.attr("href");t.preventDefault(),n.hasClass("prev")?e.page=parseInt(n.siblings(".current").text())-1:n.hasClass("next")?e.page=parseInt(n.siblings(".current").text())+1:e.page=parseInt(n.text()),e.$panel=e.$activePanel=e.$tabs.siblings(".tab-content").children(".active"),e.getComments(o)},getComments:function(t=""){e.cache[e.mode]||(e.cache[e.mode]={});var n=e.cache[e.mode],o=e.page;if(n&&n[o]){var i=n[o];!i.html.trim()&&e.$panel.data("empty")?e.$panel.html(e.$panel.data("empty")):e.$panel.html(i.html),e.$pagination.html(i.pagination),e.changeTab()}else e.$tabs.addClass("loading"),e.$activePanel.addClass("loading"),e.$pagination&&Wolmart.doLoading(e.$pagination,"small"),a.post(wolmart_vars.ajax_url,{action:this.action,nonce:wolmart_vars.nonce,post_id:this.post_id,mode:this.mode,page:this.page},(function({html:a,pagination:i}){n||(n={}),n[o]||(n[o]={}),n[o]={html:a,pagination:i},e.$pagination&&Wolmart.endLoading(e.$pagination),e.$activePanel.removeClass("loading"),e.$tabs.removeClass("loading"),!a.trim()&&e.$panel.data("empty")?e.$panel.html(e.$panel.data("empty")):e.$panel.html(a),e.$pagination.html(i),e.changeTab(),t&&history.pushState({},"",t)}))},changeTab:function(){Wolmart.loadTemplate(this.$panel),Wolmart.slider(this.$panel.find(".slider-wrapper")),this.$activePanel.removeClass("in active"),this.$panel.addClass("active in"),Wolmart.refreshLayouts()},onVoteComment:function(t){var n=a(this),o=n.data("comment_id"),i=n.hasClass("comment_help")?"fa-thumbs-up":"fa-thumbs-down";n.hasClass("already_comment")?n.parent().children(".already_vote").fadeIn().fadeOut(1e3):(n.addClass("already_comment").parent().find(".comment_unhelp").addClass("already_comment"),a("#wolmart_review_vote-"+o+" ."+i).removeClass(i).addClass("fa-spinner fas"),a.post(wolmart_vars.ajax_url,{action:"comment_vote",nonce:wolmart_vars.nonce,comment_id:o,commentvote:n.hasClass("comment_help")?"plus":"minus"},(function(a){e.$activePanel=e.$tabs.siblings(".tab-content").children(".active"),"updated"===a?(e.$activePanel.find("#wolmart_review_vote-"+o+" .fa-spinner").removeClass("fa-spinner fas").addClass(i),e.$activePanel.find("#comment"+(n.hasClass("comment_help")?"":"un")+"help-count-"+o).text(n.data("count")+1)):"voted"===a&&(e.$activePanel.find("#wolmart_review_vote-"+o+" .fa-spinner").removeClass("fa-spinner fas").addClass(i),n.parent().children(".already_vote").fadeIn().fadeOut(1e3))})))}};Wolmart.ProductHelpfulComments=e,Wolmart.$window.on("wolmart_complete",(function(){Wolmart.ProductHelpfulComments.init()}))}(jQuery);