var tdbReviewsList={};jQuery().ready(function(){tdbReviewsList.init()});
(function(){tdbReviewsList={items:[],item:function(){this.blockObj=this.uid="";this.articleAuthorID=0;this.articleAuthorBadge="";this.currentUserID=0;this._nonce=this.deleteTxt=this.requiredTxt=this.replyTxt=this.cancelReplyTxt=this.cancelTxt=this.titleTag=this.emailHolder=this.nameHolder=this.replyHolder=this.submitTxt=this.currentUserEmail=this.currentUserName="";this._is_initialized=this._in_composer=!1},init:function(){tdbReviewsList.items=[];this._is_running=!1},_initialize_item:function(a){!0!==
a._is_initialized&&(a.blockObj.on("click",".tdb-surl-review-leave-reply",function(b){b.preventDefault();b=jQuery(this);var c=b.attr("data-action"),e=b.closest(".tdb-surl-review"),g=""!==a.currentUserName&&""!==a.currentUserEmail;"reply"===c?(b.text(a.cancelReplyTxt),b.attr("data-action","cancel"),e.find("> .tdb-surl-review-right").append('<div class="tdb-surl-review-reply-form tdb-s-form tdb-s-content"><div class="tdb-s-form-content"><div class="tdb-s-fc-inner"><div class="tdb-s-form-group tdb-s-form-group-sm tdb-s-form-group-content"><textarea class="tdb-s-form-input" name="content" placeholder="'+
a.replyHolder+'"></textarea></div><div class="tdb-s-form-group tdb-s-form-group-sm tdb-s-form-group-name"><input class="tdb-s-form-input" type="text" name="name" value="'+a.currentUserName+'" '+(g?"disabled":"")+' placeholder="'+a.nameHolder+'" /></div><div class="tdb-s-form-group tdb-s-form-group-sm tdb-s-form-group-email"><input class="tdb-s-form-input" type="email" name="email" value="'+a.currentUserEmail+'" '+(g?"disabled":"")+' placeholder="'+a.emailHolder+'" /></div></div></div><div class="tdb-s-form-footer"><button class="tdb-s-btn tdb-s-btn-sm tdb-surl-review-reply-submit">'+
a.submitTxt+'</button><button class="tdb-s-btn tdb-s-btn-sm tdb-s-btn-hollow tdb-surl-review-reply-cancel">'+a.cancelTxt+"</button></div></div>"),b=e.find(".tdb-surl-review-reply-form"),jQuery("html, body").animate({scrollTop:b.offset().top-b.height()},200)):"cancel"===c&&(b.text(a.replyTxt),b.attr("data-action","reply"),e.find(".tdb-surl-review-reply-form").remove())}),a.blockObj.on("click",".tdb-surl-review-reply-cancel",function(b){var c=jQuery(this);b=c.closest(".tdb-surl-review").find(".tdb-surl-review-leave-reply");
c=c.closest(".tdb-surl-review-reply-form");b.text(a.replyTxt);b.attr("data-action","reply");c.remove()}),a.blockObj.on("click",".tdb-surl-review-reply-submit",function(b){b.preventDefault();var c=jQuery(this),e=c.closest(".tdb-surl-review");b=e.data("review-id");var g=e.find(".tdb-surl-review-leave-reply"),m=c.closest(".tdb-surl-review-reply-form"),k=m.find('[name="content"]'),h=m.find('[name="name"]'),f=m.find('[name="email"]'),l=0;m.find(".tdb-s-fg-error").removeClass(".tdb-s-fg-error");""===k.val()?
(k.closest(".tdb-s-form-group").addClass("tdb-s-fg-error"),k.closest(".tdb-s-form-group").append('<span class="tdb-s-fg-error-msg">'+a.requiredTxt+"</span>"),l++):(k.closest(".tdb-s-form-group").removeClass("tdb-s-fg-error"),k.closest(".tdb-s-form-group").find(".tdb-s-fg-error-msg").remove());""!==h.val()||h.prop("disabled")?(h.closest(".tdb-s-form-group").removeClass("tdb-s-fg-error"),h.closest(".tdb-s-form-group").find(".tdb-s-fg-error-msg").remove()):(h.closest(".tdb-s-form-group").addClass("tdb-s-fg-error"),
h.closest(".tdb-s-form-group").append('<span class="tdb-s-fg-error-msg">'+a.requiredTxt+"</span>"),l++);""!==f.val()||f.prop("disabled")?(f.closest(".tdb-s-form-group").removeClass("tdb-s-fg-error"),f.closest(".tdb-s-form-group").find(".tdb-s-fg-error-msg").remove()):(f.closest(".tdb-s-form-group").addClass("tdb-s-fg-error"),f.closest(".tdb-s-form-group").append('<span class="tdb-s-fg-error-msg">'+a.requiredTxt+"</span>"),f++);0===l&&(m.addClass("tdb-s-content-disabled"),c.addClass("tdb-s-btn-saving"),
jQuery.ajax({type:"POST",url:td_ajax_url,data:{action:"tdb_review_reply_on_submit",_nonce:a._nonce,content:k.val(),name:h.val(),email:f.val(),reviewID:b,userID:a.currentUserID},success:function(b){b=jQuery.parseJSON(b);if(""!==b.reply_id){var f=e.find(".tdb-surl-review-replies"),d="",l=a.currentUserID==a.articleAuthorID,n="";l&&(n="tdb-surl-review-reply-article-author");c.addClass("tdb-s-btn-saved");d+='<div class="tdb-surl-review tdb-surl-review-reply '+n+' tdb-s-content" data-review-reply-id="'+
b.reply_id+'">';d+='<div class="tdb-surl-review-right">';d+="<"+a.titleTag+' class="tdb-surl-review-title" '+(l?'title="Article author"':"")+">";d+=h.val();l&&(d+=a.articleAuthorBadge);d+="</"+a.titleTag+">";d+='<div class="tdb-surl-review-content">'+k.val()+"</div>";0!=a.currentUserID&&(d+='<div class="tdb-surl-review-options">',d+='<a class="tdb-surl-review-reply-delete" href="#">'+a.deleteTxt+"</a>",d+="</div>");d+="</div>";d+="</div>";setTimeout(function(){f.length?f.append(d):e.find("> .tdb-surl-review-right").append('<div class="tdb-surl-review-replies">'+
d+"</div>");m.remove();g.text(a.replyTxt);g.attr("data-action","reply")},200)}}}))}),a.blockObj.on("click",".tdb-surl-review-reply-delete",function(b){b.preventDefault();var c=jQuery(this),e=c.closest(".tdb-surl-review:not(.tdb-surl-review-reply)");b=e.data("review-id");var g=c.closest(".tdb-surl-review-reply");c=g.data("review-reply-id");g.addClass("tdb-s-content-disabled");jQuery.ajax({type:"POST",url:td_ajax_url,data:{action:"tdb_review_reply_on_delete",_nonce:a._nonce,reviewID:b,reviewReplyID:c},
success:function(a){jQuery.parseJSON(a).success&&setTimeout(function(){g.remove();var a=e.find(".tdb-surl-review-replies");a.find(".tdb-surl-review-reply").length||a.remove()},200)}})}),a._is_initialized=!0)},addItem:function(a){if("undefined"===typeof a.uid)throw"item.uid is not defined";tdbReviewsList.items.push(a);tdbReviewsList._initialize_item(a)},deleteItem:function(a){for(var b=0;b<tdbReviewsList.items.length;b++)if(tdbReviewsList.items[b].uid===a)return tdbReviewsList.items.splice(b,1),!0;
return!1},resetItems:function(){tdbReviewsList.items=[]}}})();
