(()=>{"use strict";document.addEventListener("DOMContentLoaded",(function(){const t=document.querySelector(".filters__form"),e=document.querySelector(".jb-pagination__previous"),n=document.querySelector(".jb-pagination__next"),i=document.querySelector(".jb-pagination__current-page input");let a=1,o=0,s=[],l=[],c=[];const r=document.querySelectorAll('input[name="type"]'),d=document.querySelectorAll('input[name="experience"]'),u=document.querySelectorAll('input[name="amenities"]'),p=document.querySelector(".filters__form .search"),m=document.querySelector(".location-database-listing .listing");function g(t){const e=`${window.location.origin}/wp-json/wp/v2/locations_database`,n=new URLSearchParams({page:a,per_page:12});s.length>0&&n.append("locations_database_type",s.join(",")),l.length>0&&n.append("locations_database_experiences",l.join(",")),c.length>0&&n.append("locations_database_amenities",c.join(",")),t&&n.append("search",t),fetch(`${e}?${n.toString()}`).then((t=>{o=parseInt(t.headers.get("X-WP-TotalPages"),10);const e=parseInt(t.headers.get("X-WP-Total"),10);return t.json().then((t=>{!function(t){const e=document.querySelector(".location-database-listing .listing");if(e.innerHTML="",0===t.length)return f(0,12),void(e.innerHTML='<p class="degree-plans-listing__no-results">No locations database found.</p>');t.forEach((t=>{t.locations_type&&t.locations_type.join(", "),t.locations_experience&&t.locations_experience.join(", "),t.locations_amenities&&t.locations_amenities.join(", ");const n=t.locations_amenities?t.locations_amenities.map(((t,e)=>`<li class="list-item ${e>2?"hidden":""}"><span> ${t} </span></li>`)).join(""):"",i=t.locations_amenities?Math.max(0,t.locations_amenities.length-3):0;let a="";i>0&&(a=`<span class="load-more">\n\t\t\t\t\t\t\t\t\t<i class="fa-solid fa-plus"></i>\n\t\t\t\t\t\t\t\t\t${i} More\n\t\t\t\t\t\t\t\t  </span>`);const o=`\n\t\t\t\t<div class="location-database-listing__list-item">\n\t\t\t\t\t<figure class="location-database-listing__list-item-image">\n\t\t\t\t\t\t<img src="${t.featured_image_url}" alt="${t.title.rendered}">\n\t\t\t\t\t</figure>\n\t\t\t\t\t<div class="location-database-listing__list-item-content">\n\t\t\t\t\t\t<div class="info">\n\t\t\t\t\t\t\t<h4 class="t-heading-4">${t.title.rendered}</h4>\n\t\t\t\t\t\t\t${t.acf.location.details?`\n                            <p>\n                                <i class="fa-solid fa-map-marker-alt"></i>\n                                <span>${t.acf.location.details}</span>\n                            </p>`:""}\n                            ${t.acf.contact.phone_number?`\n                            <p>\n                                <i class="fa-solid fa-phone"></i>\n                                <span>${t.acf.contact.phone_number}</span>\n                            </p>`:""}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class="lists">\n\t\t\t\t\t\t\t<ul class="list-items">\n\t\t\t\t\t\t\t\t${n}\n\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t${a}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class="location-database-listing__list-item-btn">\n\t\t\t\t\t\t<a href="${t.link}">\n\t\t\t\t\t\t\t<span>Explore</span>\n\t\t\t\t\t\t\t<i class="fa-solid fa-long-arrow-right"></i>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</div>\n\t\t\t\t</div>`;e.innerHTML+=o})),document.querySelectorAll(".load-more").forEach((t=>{t.addEventListener("click",(function(){this.previousElementSibling.querySelectorAll(".list-item.hidden").forEach((t=>t.classList.remove("hidden"))),this.style.display="none"}))})),document.querySelectorAll(".location-database-listing__list-item").forEach((t=>{t.addEventListener("click",(function(){const t=this.getAttribute("data-url");t&&(window.location.href=t)}))}))}(t),document.querySelector(".jb-pagination__current-page input").value=a,document.querySelector(".jb-pagination__total-pages").textContent=o,document.querySelector(".jb-pagination__previous").disabled=1===a,document.querySelector(".jb-pagination__next").disabled=a===o,f(e,12)}))})).catch((t=>console.error("Error fetching locations information:",t)))}function f(t,e){const n=document.querySelector(".location-database-listing__header-display-result"),i=document.querySelector(".pagination-v2");if(n&&i)if(0===t)n.style.visibility="hidden",i.style.display="none";else{n.style.visibility="visible",i.style.display=t<=e?"none":"flex";const o=(a-1)*e+1,s=(Math.min(o+e-1,t),1===t?"location meets your criteria.":"locations meet your criteria.");n.querySelector("p").textContent=`${t} ${s}`}}function h(t){return Array.from(t).filter((t=>t.checked)).map((t=>t.value))}function _(t){s=h(r),l=h(d),c=h(u),g(t),y()}function y(){const t=new URLSearchParams;s.length>0&&t.append("type",s.join(",")),l.length>0&&t.append("experience",l.join(",")),c.length>0&&t.append("amenities",c.join(","));const e=p.value.trim();e&&t.append("search",e),history.replaceState(null,"",`${window.location.pathname}?${t.toString()}`)}e.addEventListener("click",(()=>{a>1&&(a--,g())})),n.addEventListener("click",(()=>{a<o&&(a++,g())})),i.addEventListener("input",(function(){const t=parseInt(this.value,10);!isNaN(t)&&t>=1&&t<=o&&(a=t,g())})),t.addEventListener("submit",(function(t){t.preventDefault();const e=p.value.trim();a=1,_(e),y(),function(){const t=document.querySelector(".filter__heading");if(t){const e=-150,n=t.getBoundingClientRect().top+window.pageYOffset+e;window.scrollTo({top:n,behavior:"smooth"})}}()})),[r,d,u].forEach((t=>{t.forEach((t=>{t.addEventListener("change",(()=>{a=1,_(p.value.trim())}))}))})),m.addEventListener("click",(function(t){let e=t.target;for(;null!=e&&!e.classList.contains("location-database-listing__list-item");)e=e.parentElement;if(e){const t=e.getAttribute("data-url");t&&(window.location.href=t)}})),function(){const t=new URLSearchParams(window.location.search);s=t.get("type")?t.get("type").split(","):[],l=t.get("experience")?t.get("experience").split(","):[],c=t.get("amenities")?t.get("amenities").split(","):[],r.forEach((t=>{t.checked=s.includes(t.value)})),d.forEach((t=>{t.checked=l.includes(t.value)})),u.forEach((t=>{t.checked=c.includes(t.value)}));const e=t.get("search")||"";p.value=e,g()}()}))})();