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,parentItem:n}=t,o=Joomla.getOptions("sppb-root"),a=await fetch(`${o}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),currentLink:window.location.search.replace("?",""),isSite:!window.location.pathname.includes("/edit")&&!window.location.pathname.includes("/edit/"),parent_item:JSON.stringify(n)})});return await a.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),c=t.dataset.parentItem?JSON.parse(t.dataset.parentItem):null;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,parentItem:c});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,i=n.dataset.parentItem?JSON.parse(n.dataset.parentItem):null;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,parentItem:i});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()}));