if(HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules")){const t={prerender:[{eagerness:"moderate",where:{and:[{selector_matches:"[data-preload-collection]"}]}}]},e=document.createElement("script");e.type="speculationrules",e.textContent=JSON.stringify(t),document.head.appendChild(e)}let currentPage=1;async function loadMoreData(t){const{addon:e}=t,n=Joomla.getOptions("sppb-root"),o=await fetch(`${n}index.php?option=com_sppagebuilder&task=dynamic_content.loadMoreCollectionData`,{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-Token":Joomla.getOptions("csrf.token")},body:JSON.stringify({collection_id:Number(e?.settings?.source??0),filters:JSON.stringify(e?.settings?.filters??[]),limit:Number(e?.settings?.limit??20),direction:e?.settings?.direction??"ASC",page:++currentPage,addon:JSON.stringify(e)})});return await o.json()}function loadDataByClickingLoadMoreButton(){document.querySelectorAll("[data-sppb-load-more-button]").forEach((t=>{const e=t.closest(".addon-root-dynamic-content-collection"),n=e.querySelector(".sppb-dynamic-content-collection"),o=t.closest(".sppb-dynamic-content-collection__pagination"),a=o.querySelector('[name="sppb-dynamic-addon-id"]')?.value,i=Joomla.getOptions("sppb-dc-addon-"+a);a&&i&&e&&n&&o&&t.addEventListener("click",(async function(e){e.preventDefault();const o=t.dataset.totalPages;t.textContent="Loading...";const a=await loadMoreData({currentPage:currentPage,addon:i});t.textContent=t.dataset.text,a.data&&n.insertAdjacentHTML("beforeend",a.data),t.dataset.currentPage=currentPage,currentPage>=o&&t.remove()}))}))}function loadDataByIntersectionObserver(){const t=document.querySelector(".sppb-dynamic-content-collection__pagination-sentinel"),e=t.closest(".addon-root-dynamic-content-collection").querySelector(".sppb-dynamic-content-collection"),n=t.closest(".sppb-dynamic-content-collection__pagination"),o=n.querySelector('[name="sppb-dynamic-addon-id"]')?.value,a=t.dataset.totalPages;new IntersectionObserver((async n=>{if(n[0].isIntersecting&&currentPage<a){t.style.visibility="visible";const n=Joomla.getOptions("sppb-dc-addon-"+o),a=await loadMoreData({addon:n});e.insertAdjacentHTML("beforeend",a.data),t.style.visibility="hidden"}}),{rootMargin:"50px"}).observe(t)}window.addEventListener("DOMContentLoaded",(function(){const t=document.querySelector('[name="sppb-dc-pagination-type"]')?.value;"infinite-scroll"===t?loadDataByIntersectionObserver():loadDataByClickingLoadMoreButton()}));