document.addEventListener("DOMContentLoaded",function(){const t=document.querySelector(".wp-block-carhop-blocks-dbmob-archives");if(!t)return;const e=t.querySelector(".notices-toolbar");if(!e)return;const r=e.querySelector("input[name='search']"),o=e.querySelector("select[name='sort_by']"),n=t.querySelector(".load-more-button");let c=null,s=0;async function a(){var e,n;const a=null!==(e=r?.value)&&void 0!==e?e:"",l=null!==(n=o?.value)&&void 0!==n?n:"date_desc",u=`/wp-json/carhop-datas/v1/build/posts?${new URLSearchParams({sort_by:l,recherche:a,post_type:"dbmob",offset:String(0),posts_per_page:String(-1)}).toString()}`;c&&c.abort(),c=new AbortController;const i=++s;try{const e=await fetch(u,{signal:c.signal});if(!e.ok)throw new Error(`HTTP ${e.status}`);const r=await e.json();if(i!==s)return;const o=t.querySelector(".dbmob-grid");if(!o)return;o.innerHTML=r.html_template,function(e){const r=t.querySelector(".post-count__count");null!=r&&null!=e&&(r.textContent=String(e))}(r.post_count)}catch(t){if("AbortError"===t?.name)return;console.error("Erreur lors de la récupération des articles:",t)}}const l=function(t){let e;return(...r)=>{e&&window.clearTimeout(e),e=window.setTimeout(()=>t(...r),150)}}(a);o&&o.addEventListener("change",t=>{t.target.value,a()}),r&&r.addEventListener("input",()=>{l()}),n&&n.addEventListener("click",()=>{n.dataset.offset,n.dataset.postsPerPage,a()})});