if(HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules")){const e={prerender:[{eagerness:"moderate",where:{and:[{selector_matches:"[data-preload-collection]"}]}}]},t=document.createElement("script");t.type="speculationrules",t.textContent=JSON.stringify(e),document.head.appendChild(t)}let currentPage=1;async function loadMoreData(e){const{addon:t}=e,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(t?.settings?.source??0),filters:JSON.stringify(t?.settings?.filters??[]),limit:Number(t?.settings?.limit??20),direction:t?.settings?.direction??"ASC",page:++currentPage,addon:JSON.stringify(t),currentLink:window.location.search.replace("?",""),isSite:!window.location.pathname.includes("/edit")&&!window.location.pathname.includes("/edit/")})});return await o.json()}function loadDataByClickingLoadMoreButton(){document.querySelectorAll("[data-sppb-load-more-button]").forEach((e=>{const t=e.closest(".addon-root-dynamic-content-collection"),n=t.querySelector(".sppb-dynamic-content-collection"),o=e.closest(".sppb-dynamic-content-collection__pagination"),a=o.querySelector('[name="sppb-dynamic-addon-id"]')?.value,i=Joomla.getOptions("sppb-dc-addon-"+a);a&&i&&t&&n&&o&&e.addEventListener("click",(async function(t){t.preventDefault();const o=e.dataset.totalPages;e.textContent="Loading...";const a=await loadMoreData({currentPage:currentPage,addon:i});e.textContent=e.dataset.text,a.data&&n.insertAdjacentHTML("beforeend",a.data),e.dataset.currentPage=currentPage,currentPage>=o&&e.remove()}))}))}function loadDataByIntersectionObserver(){const e=document.querySelector(".sppb-dynamic-content-collection__pagination-sentinel"),t=e.closest(".addon-root-dynamic-content-collection").querySelector(".sppb-dynamic-content-collection"),n=e.closest(".sppb-dynamic-content-collection__pagination"),o=n.querySelector('[name="sppb-dynamic-addon-id"]')?.value,a=e.dataset.totalPages;new IntersectionObserver((async n=>{if(n[0].isIntersecting&&currentPage<a){e.style.visibility="visible";const n=Joomla.getOptions("sppb-dc-addon-"+o),a=await loadMoreData({addon:n});t.insertAdjacentHTML("beforeend",a.data),e.style.visibility="hidden"}}),{rootMargin:"50px"}).observe(e)}window.addEventListener("DOMContentLoaded",(function(){const e=document.querySelector('[name="sppb-dc-pagination-type"]')?.value;"infinite-scroll"===e?loadDataByIntersectionObserver():loadDataByClickingLoadMoreButton()}));