var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):$jscomp.arrayIterator(a)};$jscomp.arrayFromIterator=function(a){for(var b,c=[];!(b=a.next()).done;)c.push(b.value);return c};
$jscomp.arrayFromIterable=function(a){return a instanceof Array?a:$jscomp.arrayFromIterator($jscomp.makeIterator(a))};var tdbPostsList={};jQuery().ready(function(){tdbPostsList.init()});
(function(){tdbPostsList={items:[],item:function(){this.blockObj=this.uid="";this.renderOptions={};this.activeFilters={};this.confirmModals=[];this.topNotifications=[];this._is_initialized=!1},init:function(){tdbPostsList.items=[];this._is_running=!1},addItem:function(a){if("undefined"===typeof a.uid)throw"item.uid is not defined";tdbPostsList.items.push(a);tdbPostsList._initialize_item(a)},deleteItem:function(a){for(var b=0;b<tdbPostsList.items.length;b++)if(tdbPostsList.items[b].uid===a)return tdbPostsList.items.splice(b,
1),!0;return!1},resetItems:function(){tdbPostsList.items=[]},renderPosts:function(a){var b=a.blockObj.find(".tdb-block-inner");jQuery.when(jQuery.ajax({type:"POST",url:td_ajax_url,data:{action:"tdb_get_posts_list_posts",_ajax_nonce:a.blockObj.find("#tdb_posts_list_nonce").val(),options:JSON.stringify(a.renderOptions),activeFilters:JSON.stringify(a.activeFilters)},success:function(a){a=jQuery.parseJSON(a);""!==a.html&&b.html(a.html)}})).done(function(){a.blockObj.trigger("postsList.rendered")})},onSearch:function(a,
b,c){a.blockObj.trigger("postsList.rendering");a.activeFilters.search={keyword:b,in:c};tdbPostsList.renderPosts(a)},onSortByColumn:function(a,b){a.blockObj.trigger("postsList.rendering");"undefined"!==typeof a.activeFilters.columnSort&&a.activeFilters.columnSort.name===b?a.activeFilters.columnSort.order="ASC"===a.activeFilters.columnSort.order?"DESC":"ASC":a.activeFilters.columnSort={name:b,order:"ASC"};tdbPostsList.renderPosts(a)},onPagination:function(a,b){a.blockObj.trigger("postsList.rendering");
a.renderOptions.currentPage=b;tdbPostsList.renderPosts(a)},onChangePostStatus:function(a,b,c,e){var d=new tdbModal.item;d.customClasses="tdb-plist-confirm-modal tdb-plist-confirm-modal-"+a.uid;d.title=tdbPostsList._stringFromBinary(a.confirmModals.publish.title);d.body='<div class="tdb-s-modal-txt">'+tdbPostsList._stringFromBinary(a.confirmModals.publish.body).replace("%POST_TITLE%",c)+"</div>";d.cancelBtnTxt=window.tdb_modal_cancel_alt;d.confirmBtnTxt=window.tdb_modal_confirm_alt;tdbModal.addItem(d);
tdbModal.openModal(d);d.modalObj.on("tdbModal.confirming",function(){d.modalObj.trigger("tdbModal.confirmed")});d.modalObj.on("tdbModal.confirmed",function(){a.blockObj.trigger("postsList.rendering");jQuery.ajax({method:"POST",url:td_ajax_url,data:{action:"tdb_posts_list_update_post_status",_ajax_nonce:a.blockObj.find("#tdb_posts_list_nonce").val(),postID:b,newStatus:e},success:function(c){c=jQuery.parseJSON(c);if(""!==c.success){a.topNotifications.push({message:c.success,type:"success"});var d=a.blockObj.find('.tdb-plist-post[data-post-id="'+
b+'"]'),e=d.find(".tdb-plist-publish-post");d.find(".tdb-s-table-col-title .tdb-plist-title-status").remove();e.prev().remove();e.remove()}""!==c.error&&a.topNotifications.push({message:c.error,type:"error"});a.blockObj.trigger("postsList.rendered")}})})},onDeletePost:function(a,b,c){var e=a.blockObj.find(".tdb-block-inner"),d=new tdbModal.item;d.customClasses="tdb-plist-confirm-modal tdb-plist-confirm-modal-"+a.uid;d.title=tdbPostsList._stringFromBinary(a.confirmModals.delete.title);d.body='<div class="tdb-s-modal-txt">'+
tdbPostsList._stringFromBinary(a.confirmModals.delete.body).replace("%POST_TITLE%",c)+"</div>";d.cancelBtnTxt=window.tdb_modal_cancel_alt;d.confirmBtnTxt=window.tdb_modal_confirm_alt;tdbModal.addItem(d);tdbModal.openModal(d);d.modalObj.on("tdbModal.confirming",function(){d.modalObj.trigger("tdbModal.confirmed")});d.modalObj.on("tdbModal.confirmed",function(){a.blockObj.trigger("postsList.rendering");jQuery.ajax({type:"POST",url:td_ajax_url,data:{action:"tdb_posts_list_delete_post",_ajax_nonce:a.blockObj.find("#tdb_posts_list_nonce").val(),
postID:b},success:function(c){c=jQuery.parseJSON(c);""!==c.success&&(a.topNotifications.push({message:c.success,type:"success"}),1===e.find(".tdb-plist-post").length&&a.renderOptions.currentPage--,tdbPostsList.renderPosts(a));""!==c.error&&(a.topNotifications.push({message:c.error,type:"error"}),a.blockObj.trigger("postsList.rendered"))}})})},topNotifications:function(a){if(!a.topNotifications.length)return!1;var b=a.blockObj.find(".tdb-block-inner"),c=b.find(".tdb-plist-notifs-top");c.length||(b.prepend('<div class="tdb-plist-notifs-top"></div>'),
c=b.find(".tdb-plist-notifs-top"));jQuery.each(a.topNotifications,function(a,b){c.prepend('<div class="tdb-s-notif tdb-s-notif-sm tdb-s-notif-'+b.type+'"><div class="tdb-s-notif-descr">'+b.message+"</div></div>")});a.topNotifications=[];setTimeout(function(){c.remove()},5E3)},_initialize_item:function(a){if(!0!==a._is_initialized){var b=a.blockObj.find(".tdb-block-inner");a.blockObj.on("postsList.rendering",function(){b.hasClass("tdb-s-content-loading")||b.addClass("tdb-s-content-loading")});a.blockObj.on("postsList.rendered",
function(){tdbPostsList.topNotifications(a);b.hasClass("tdb-s-content-loading")&&b.removeClass("tdb-s-content-loading")});a.blockObj.on("keydown",".tdb-plist-search .tdb-plist-search-keyword",function(a){13===a.keyCode&&jQuery(this).closest(".tdb-plist-search").find("button").click()});a.blockObj.on("click",".tdb-plist-search button",function(c){c.preventDefault();var b=jQuery(this).closest(".tdb-plist-search");c=b.find(".tdb-plist-search-keyword").val();b=b.find(".tdb-plist-search-in").val();tdbPostsList.onSearch(a,
c,b)});a.blockObj.on("click",".tdb-s-table-header th",function(){var c=jQuery(this).data("column");tdbPostsList.onSortByColumn(a,c)});a.blockObj.on("click",".tdb-plist-publish-post",function(c){c.preventDefault();var b=jQuery(this);c=b.data("post-id");b=b.data("post-title");tdbPostsList.onChangePostStatus(a,c,b,"publish")});a.blockObj.on("click",".tdb-plist-delete-post",function(b){b.preventDefault();var c=jQuery(this);b=c.data("post-id");c=c.data("post-title");tdbPostsList.onDeletePost(a,b,c)});
a.blockObj.on("click",".tdb-s-pagination-item",function(b){b.preventDefault();b=jQuery(this).data("page");tdbPostsList.onPagination(a,b)});a._is_initialized=!0}},_stringToBinary:function(a){for(var b=new Uint16Array(a.length),c=0;c<b.length;c++)b[c]=a.charCodeAt(c);return btoa(String.fromCharCode.apply(String,$jscomp.arrayFromIterable(new Uint8Array(b.buffer))))},_stringFromBinary:function(a){a=atob(a);for(var b=new Uint8Array(a.length),c=0;c<b.length;c++)b[c]=a.charCodeAt(c);return String.fromCharCode.apply(String,
$jscomp.arrayFromIterable(new Uint16Array(b.buffer)))}}})();
