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)}async function loadMoreData(t){const{addon:e,parentItem:n,currentPage:o}=t,a=Joomla.getOptions("sppb-root"),i=await fetch(`${a}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),sortingColumn:e?.settings?.field_sorting?e?.settings?.sorting_field_id??null:null,direction:e?.settings?.direction??"ASC",page:o,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 i.json()}function loadDataByClickingLoadMoreButton(){document.querySelectorAll("[data-sppb-load-more-button]").forEach((t=>{let e=Number(t.dataset.currentPage)||1;const n=t.closest(".addon-root-dynamic-content-collection"),o=n.querySelector(".sppb-dynamic-content-collection"),a=t.closest(".sppb-dynamic-content-collection__pagination"),i=a.querySelector('[name="sppb-dynamic-addon-id"]')?.value,r=Joomla.getOptions("sppb-dc-addon-"+i),c=t.dataset.parentItem?JSON.parse(t.dataset.parentItem):null;i&&r&&n&&o&&a&&t.addEventListener("click",(async function(n){n.preventDefault();const a=Number(t.dataset.totalPages);t.textContent="Loading...",e++;const i=await loadMoreData({currentPage:e,addon:r,parentItem:c});t.textContent=t.dataset.text,i.data&&o.insertAdjacentHTML("beforeend",i.data),t.dataset.currentPage=e,e>=a&&t.remove()}))}))}function loadDataByIntersectionObserver(){document.querySelectorAll(".sppb-dynamic-content-collection__pagination-sentinel").forEach((t=>{let e=Number(t.dataset.currentPage)||1;const n=t.closest(".addon-root-dynamic-content-collection").querySelector(".sppb-dynamic-content-collection"),o=t.closest(".sppb-dynamic-content-collection__pagination"),a=o.querySelector('[name="sppb-dynamic-addon-id"]')?.value,i=Number(t.dataset.totalPages),r=o.dataset.parentItem?JSON.parse(o.dataset.parentItem):null;new IntersectionObserver((async o=>{if(o[0].isIntersecting&&e<i){t.style.visibility="visible";const o=Joomla.getOptions("sppb-dc-addon-"+a);e++;const i=await loadMoreData({currentPage:e,addon:o,parentItem:r});n.insertAdjacentHTML("beforeend",i.data),t.style.visibility="hidden",t.dataset.currentPage=e}}),{rootMargin:"50px"}).observe(t)}))}window.addEventListener("DOMContentLoaded",(function(){const t=Array.from(document.querySelectorAll('[name="sppb-dc-pagination-type"]')).map((t=>t.value));[...new Set(t)].forEach((t=>{"infinite-scroll"===t?loadDataByIntersectionObserver():loadDataByClickingLoadMoreButton()}))}));