function GSshowPreloaderAPI(e,t){let a=e.getAttribute("data-api-loader-selector"),r="";a&&(r=document.querySelector(a));let s;if(r)r.classList.add("active");else{s=`
    <div class="gspb_query_preloader">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="60" viewBox="0 0 100 100" class="preloadersvg" fill="#2184f9">
            <path d="M73,50c0-12.7-10.3-23-23-23S27,37.3,27,50 M30.9,50c0-10.5,8.5-19.1,19.1-19.1S69.1,39.5,69.1,50">
                <animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="1s" from="0 50 50" to="360 50 50" repeatCount="indefinite"/>
            </path>
        </svg>
    </div>
`,e.insertAdjacentHTML("afterend",s);let i=e.nextElementSibling;i.offsetWidth,i.classList.add("active")}}function GSremovePreloaderAPI(e){let t=e.getAttribute("data-api-loader-selector"),a="";if(t&&(a=document.querySelector(t)),a)a.classList.remove("active");else{let r=e.nextElementSibling;r&&r.classList.contains("gspb_query_preloader")&&(r.classList.remove("active"),r.classList.add("fade-out"),r.addEventListener("transitionend",function(){r.remove()},{once:!0}))}}document.addEventListener("DOMContentLoaded",()=>{let e=document.querySelectorAll("[data-dynamic-api]");e.forEach(e=>{let t=e.getAttribute("data-api-id"),a=e.getAttribute("api-form-selector"),r=e.getAttribute("data-dynamic-api-trigger"),s=e.getAttribute("data-api-run-index");s=s?parseInt(s):-1;let i=e.getAttribute("data-api-pagination-selector"),n="";if(i&&(n=document.querySelector(i))&&n.addEventListener("click",a=>{a.preventDefault();let r=e.getAttribute("data-api-run-index");r&&(r=parseInt(r)),GSPB_Connector_API_Run(e,t,[],r+1)}),"form"===r&&a){let o=document.querySelector(a);o&&o.addEventListener("submit",a=>{a.preventDefault();let r=new FormData(o),i={};r.forEach((e,t)=>{i.hasOwnProperty(t)?(Array.isArray(i[t])||(i[t]=[i[t]]),i[t].push(e)):i[t]=e}),GSPB_Connector_API_Run(e,t,i,s)})}else"custom"===r||"load"===r&&GSPB_Connector_API_Run(e,t,[],s)})});const GSPB_Connector_API_Run=(e,t,a=null,r=0)=>{e.classList.remove("loaded"),e.classList.remove("error"),e.classList.remove("active"),e.classList.add("loading"),r++,e.setAttribute("data-api-run-index",r);let s=e.getAttribute("data-api-pagination-selector"),i="";s&&(i=document.querySelector(s)),GSshowPreloaderAPI(e,t);let n={api_id:t,formdata:a,nonce:gspbapi_connector_vars.nonce,runindex:r,page:i?r+1:null};fetch(gspbapi_connector_vars.rest_url,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":gspbapi_connector_vars.nonce},body:JSON.stringify(n)}).then(function(e){return e.json().then(function(t){return{status:e.status,data:t}})}).then(function(t){let a=t.status,r=t.data;if(GSremovePreloaderAPI(e),r.length&&200===a){let s=e.getAttribute("data-api-show-method");if("append"===s?e.insertAdjacentHTML("beforeend",r):"prepend"===s?e.insertAdjacentHTML("afterbegin",r):(e.innerHTML="",e.insertAdjacentHTML("beforeend",r)),e.classList.remove("loading"),Array.from(e.children).forEach(e=>{e.classList.contains("result-loaded")||setTimeout(()=>{e.classList.add("result-loaded")},10)}),setTimeout(()=>{e.classList.add("loaded"),e.classList.add("active"),i&&i.classList.add("active")},50),e.closest(".gs-swiper-init")){e.closest(".gs-swiper-init").querySelector(".swiper").swiper.destroy();GSPB_render_Swiper(e.closest(".gs-swiper-init"))}let n=e.querySelectorAll("[data-gspbactions]");n.length>0&&"function"==typeof GSPB_Trigger_Actions&&GSPB_Trigger_Actions("front",n),"undefined"!=typeof GSChartRun&&GSChartRun(e),document.dispatchEvent(new CustomEvent("GSPB_API_RESPONSE",{detail:{item:e,data:r}}))}else resultsContainer.innerHTML="No results found"}).catch(t=>{console.error("Fetch Error:",t),GSremovePreloaderAPI(e),e.classList.remove("loading"),e.classList.add("error")})};