(()=>{function t(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,a)}return s}function e(e){for(var a=1;a<arguments.length;a++){var i=null!=arguments[a]?arguments[a]:{};a%2?t(Object(i),!0).forEach((function(t){s(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function s(t,e,s){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var s=e.call(t,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}void 0===TCB_Front.js_modules.pagination&&TCB_Front.setModuleLoadedStatus("pagination",!1),function(t){if(TCB_Front.isModuleLoaded("pagination"))return;const s="tcb-pagination-number",a="tcb-pagination-current",i="tcb-pagination-dots",r="tcb-pagination-link",n="tcb-pagination-button",o="tcb-permanently-hidden";class l{constructor(e,s){this.type=e,this.list=s,this.$element=t(`.tcb-pagination[data-list="${this.list.identifier}"]`)}static factory(t,s){let a,i={load_more:g,numeric:c};const r=ThriveGlobal.$j.Event("tcb_pagination_extra_classes.tcb");return s.$element.trigger(r),r.paginationClasses&&(i=e(e({},i),r.paginationClasses)),void 0===i[t]?console.warn("A pagination class for this type does not exist!"):a=i[t],new a(t,s)}addLoadListeners(){console.warn("Overwrite this function!")}load(){console.warn("Overwrite this function!")}render(){console.warn("Overwrite this function!")}isLoading(){return this.list.isLoading()}enableLoading(t=""){this.list.enableLoading(t)}disableLoading(){this.list.disableLoading()}getTotalPostCount(){let t=0;return t+=Number(this.list.listArgs.attr.total_post_count)||0,t+=Number(this.list.listArgs.attr.total_sticky_count)||0,t}}class c extends l{constructor(t,e){super(t,e);const s=this.list.listArgs;this.firstPage=1,this.postsPerPage=Math.max(parseInt(s.query?s.query.posts_per_page:s.attr.posts_per_page),1),this.lastPage=Math.ceil(this.getTotalPostCount()/this.postsPerPage),this.currentPage=parseInt(s.query?s.query.paged:s.attr.paged),this.pagesAroundCurrent=parseInt(s.attr.pages_near_current),this.totalPages=this.lastPage,this.buttons={},this.$element.attr("data-ct")||this.$element.attr({"data-ct":"pagination-123","data-ct-name":"Default"}),["first","last","prev","next"].forEach((t=>{const e=this.$element.find(`.${n}.tcb-pagination-${t}`);switch(t){case"first":case"last":e.attr("data-page",this[`${t}Page`])}e.find('a[href="#"]').each(((t,e)=>e.setAttribute("href","javascript:void(0)"))),this.buttons["$"+t]=e})),this.$pageNumberContainer=this.$element.find(".tcb-pagination-numbers-wrapper"),this.$label=this.$element.find(".tcb-pagination-label")}static renderPageNumber(e,n=""){const o=[s,"thrv_wrapper"];let l,c={};switch(n){case"current":o.push(a),l=`.${a}`;break;case"dots":o.push(i),l=`.${i}`,e="...";break;case"link":o.push(r),l=`.${r}`,c={"data-page":e},e=`<a href="javascript:void(0)">${e}</a>`}return c["data-selector"]=l,t(`<p>${e}</p>`).addClass(o.join(" ")).attr(c)}addLoadListeners(){this.$element.on("click",`.${n}`,(e=>{const s=t(e.target).closest(`.${n}`);this.load(s.attr("data-page"))})),this.$element.on("click",`.${s}:not(.${a}, .${i})`,(t=>this.load(t.currentTarget.dataset.page))),t("body").off("tcb_post_list_filter_change").on("tcb_post_list_filter_change",(()=>{this.$element.trigger("tcb_after_numeric_pagination_render",this)}))}load(t){if(t&&!this.isLoading()){this.enableLoading(),this.currentPage=parseInt(t);const e=this.list.listArgs;void 0===e.query?e.attr.paged=this.currentPage:e.query.paged=this.currentPage,this.list.getItems((t=>{this.list.insertItems(t,!0),this.render(),this.disableLoading()}),e)}}render(){this.lastPage=Math.ceil(this.getTotalPostCount()/this.postsPerPage),this.renderButtons(),this.renderLabel(),this.renderPageNumbers(),this.$element.trigger("tcb_after_numeric_pagination_render",this),this.$element.removeClass(o)}renderButtons(){this.buttons.$prev.attr("data-page",this.currentPage-1),this.buttons.$next.attr("data-page",this.currentPage+1);const t=1===parseInt(tve_frontend_options.is_editor_page);[this.buttons.$first,this.buttons.$prev].forEach((e=>{e.hasClass(o)||e.toggleClass("tcb-disabled-pagination-button",!t&&this.currentPage<=this.firstPage)})),[this.buttons.$last,this.buttons.$next].forEach((e=>{e.hasClass(o)||e.toggleClass("tcb-disabled-pagination-button",!t&&this.currentPage>=this.lastPage)}))}renderLabel(){this.$label.find(".thrive-shortcode-content").each(((t,e)=>{const s=e.dataset.shortcode;e.innerText=` ${this.getLabelValue(s)} `}))}getLabelValue(t){let e;switch(t){case"tcb_pagination_current_page":e=this.currentPage;break;case"tcb_pagination_total_pages":e=this.lastPage;break;case"tcb_pagination_current_posts":e=(this.currentPage-1)*this.postsPerPage+1+"-"+this.currentPage*this.postsPerPage;break;case"tcb_pagination_total_posts":e=this.totalPages*this.postsPerPage;break;default:e=""}return e}renderPageNumbers(){this.$pageNumberContainer.empty();let t=!0;for(let e=1;e<=this.lastPage;e++){let s;if(e===this.currentPage)s="current";else if(1===e||e>=this.currentPage-this.pagesAroundCurrent&&e<=this.currentPage+this.pagesAroundCurrent||e===this.totalPages)s="link",t=!0;else{if(s="dots",!t)continue;t=!1}this.$pageNumberContainer.append(c.renderPageNumber(e,s))}}}class g extends l{constructor(t,e){super(t,e),this.$button=this.$element.find(".tcb-pagination-load-more-button")}addLoadListeners(){this.$button.on("click",this.load.bind(this))}load(){if(!this.isLoading()){this.enableLoading("load-bot");const t=this.list.listArgs;if(void 0===t.query?t.attr.paged+=1:t.query.paged+=1,t.query&&"rand"===t.query.orderby){const e=[];this.list.$element.find("article").each(((t,s)=>{e.push(parseInt(s.getAttribute("data-id")))})),t.query.post__not_in=e,t.query.paged=1}this.list.getItems((t=>{this.list.insertItems(t),this.render(),this.disableLoading()}),t)}}render(){const t=this.list.listArgs,e=1===parseInt(tve_frontend_options.is_editor_page);let s;s=t.query?t.query.paged*t.query.posts_per_page:t.attr.paged*t.attr.posts_per_page,this.$element.toggle(e||s<this.getTotalPostCount()),this.$element.find(".tcb-pagination-load-more-link").attr("href","javascript:void(0)"),this.$element.removeClass(o)}}window.TCB_Front.Pagination=l,TCB_Front.setModuleLoadedStatus("pagination",!0)}(ThriveGlobal.$j)})();