1import{b as h}from"/assets/chunks/chunk-KWI774O3.js";import"/assets/chunks/chunk-XDTPXY5K.js";var l=class extends h{static targets=["productsGrid","button","pagyNav","pagyInfo","layoutButton","title","description","spinner"];connect(){this._abortController=null,this._layoutCache={},this.buttonTargets.forEach(t=>{let e=new URLSearchParams(window.location.search);(e.get("sort")===t.dataset.sort||e.get("sort")===null&&t.dataset.sort==="most_popular"&&!window.location.pathname.includes("/categories/"))&&t.classList.add("active")});let s=new URLSearchParams(window.location.search),a=s.get("layout")||"grid";this.updateLayoutButtons(a),this.updateLayoutClass(a),this.updateTitle(s.get("sort")),this.updateDescription(s.get("sort")),this.stopLoading(),this._layoutCache[a]={html:this.productsGridTarget.innerHTML,pagy_nav:this.hasPagyNavTarget?this.pagyNavTarget.innerHTML:null,pagy_info:this.hasPagyInfoTarget?this.pagyInfoTarget.innerHTML:null},this.hasPagyNavTarget&&(this._onCipherNavigate=t=>{t.preventDefault(),t.stopImmediatePropagation();let e=t.detail?.href;e&&this._fetchPage(e)},this.pagyNavTarget.addEventListener("cipher:navigate",this._onCipherNavigate,{capture:!0}),this._onPagyClick=t=>{let e=t.target instanceof Element?t.target.closest("a"):null;if(!e||e.hasAttribute("data-qcd")||e.closest('[data-controller~="cipher"]'))return;t.preventDefault(),t.stopImmediatePropagation();let o=e.getAttribute("href");!o||o==="#"||this._fetchPage(o)},this.pagyNavTarget.addEventListener("click",this._onPagyClick,{capture:!0}))}disconnect(){this._abortController&&this._abortController.abort(),this.hasPagyNavTarget&&(this._onCipherNavigate&&this.pagyNavTarget.removeEventListener("cipher:navigate",this._onCipherNavigate,{capture:!0}),this._onPagyClick&&this.pagyNavTarget.removeEventListener("click",this._onPagyClick,{capture:!0}))}
1_fetchPage(s){this._layoutCache={};let a=new URL(s,window.location.origin),t=new URLSearchParams(window.location.search).get("layout")||"grid";a.searchParams.set("layout",t),window.history.pushState({},"",a),this.startLoading(),this._abortController&&this._abortController.abort(),this._abortController=new AbortController,fetch(a,{signal:this._abortController.signal,headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest","X-CSRF-Token":window.getCsrfToken()}}).then(e=>e.json()).then(e=>{this.updateTitle(a.searchParams.get("sort")),this.updateDescription(a.searchParams.get("sort")),this.productsGridTarget.innerHTML=e.html,this.hasPagyNavTarget&&(this.pagyNavTarget.innerHTML=e.pagy_nav),this.hasPagyInfoTarget&&(this.pagyInfoTarget.innerHTML=e.pagy_info),this.updateLayoutClass(t)}).catch(e=>{e.name!=="AbortError"&&console.error(e)}).finally(()=>this.stopLoading())}filter(s){s.preventDefault(),this._layoutCache={};let a=s.currentTarget,t=a.dataset.sort;this.buttonTargets.forEach(i=>i.classList.remove("active")),a.classList.add("active");let e=new URL(window.location);e.searchParams.set("sort",t),e.searchParams.delete("page"),window.history.pushState({},"",e);let o=new URLSearchParams(window.location.search).get("layout")||"grid",n=`${window.location.pathname}?sort=${t}&layout=${o}`;this.startLoading(),this._abortController&&this._abortController.abort(),this._abortController=new AbortController,fetch(n,{signal:this._abortController.signal,headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest","X-CSRF-Token":window.getCsrfToken()}}).then(i=>i.json()).then(i=>{this.updateTitle(t),this.updateDescription(t),this.productsGridTarget.innerHTML=i.html,this.hasPagyNavTarget&&(this.pagyNavTarget.innerHTML=i.pagy_nav),this.hasPagyInfoTarget&&(this.pagyInfoTarget.innerHTML=i.pagy_info),this.updateLayoutClass(o)}).catch(i=>{i.name!=="AbortError"&&console.error(i)}).finally(()=>this.stopLoading())}updateTitle(s){if(this.hasTitleTarget){let a=JSON.parse(this.titleTarget.dataset.titles),t;switch(s){case"most_popular":t=a.most_popular;break;case"premium":t=a.premium;break;case"free":t=a.free;break;case"recently_added":t=a.recently_added;break;default:t=a.default}this.titleTarget.textContent=t}}updateDescription(s){if(this.hasDescriptionTarget){let a=JSON.parse(this.descriptionTarget.dataset.descriptions),t;switch(s){case"most_popular":t=a.most_popular;break;case"premium":t=a.premium;break;case"free":t=a.free;break;case"recently_added":t=a.recently_added;break;default:t=a.default}this.descriptionTarget.textContent=t}}switchLayout(s){s.preventDefault();let t=s.currentTarget.dataset.layout,e=new URLSearchParams(window.location.search).get("layout")||"grid",o=this.productsGridTarget.innerHTML,n=this._layoutCac
1he[e];n&&n.html!==o&&(this._layoutCache={}),this._layoutCache[e]={html:o,pagy_nav:this.hasPagyNavTarget?this.pagyNavTarget.innerHTML:null,pagy_info:this.hasPagyInfoTarget?this.pagyInfoTarget.innerHTML:null};let i=new URL(window.location);if(i.searchParams.set("layout",t),window.history.pushState({},"",i),this.updateLayoutButtons(t),this._layoutCache[t]){let r=this._layoutCache[t];this.productsGridTarget.innerHTML=r.html,this.hasPagyNavTarget&&r.pagy_nav&&(this.pagyNavTarget.innerHTML=r.pagy_nav),this.hasPagyInfoTarget&&r.pagy_info&&(this.pagyInfoTarget.innerHTML=r.pagy_info),this.updateLayoutClass(t);return}this.startLoading(),this._abortController&&this._abortController.abort(),this._abortController=new AbortController,fetch(i,{signal:this._abortController.signal,headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest","X-CSRF-Token":window.getCsrfToken()}}).then(r=>r.json()).then(r=>{this.productsGridTarget.innerHTML=r.html,this.hasPagyNavTarget&&(this.pagyNavTarget.innerHTML=r.pagy_nav),this.hasPagyInfoTarget&&(this.pagyInfoTarget.innerHTML=r.pagy_info),this._layoutCac
1he[t]={html:this.productsGridTarget.innerHTML,pagy_nav:this.hasPagyNavTarget?this.pagyNavTarget.innerHTML:null,pagy_info:this.hasPagyInfoTarget?this.pagyInfoTarget.innerHTML:null},this.updateLayoutClass(t)}).catch(r=>{r.name!=="AbortError"&&console.error(r)}).finally(()=>this.stopLoading())}updateLayoutButtons(s){this.layoutButtonTargets.forEach(a=>{a.classList.toggle("active",a.dataset.layout===s);let t=a.querySelector("img");t&&t.classList.toggle("filter-white",a.dataset.layout===s)})}updateLayoutClass(s){s==="list"?(this.productsGridTarget.classList.remove("grid-cols-1","md:grid-cols-2","lg:grid-cols-3"),this.productsGridTarget.classList.add("grid-cols-1")):(this.productsGridTarget.classList.remove("grid-cols-1"),this.productsGridTarget.classList.add("grid-cols-1","md:grid-cols-2","lg:grid-cols-3"))}startLoading(){this._loadingAt=performance.now(),this.hasSpinnerTarget&&(this.spinnerTarget.classList.remove("hidden"),this.spinnerTarget.getBoundingClientRect());let s=this.productsGridTarget;this._gridMinH=s.offsetHeight,s.style.minHeight=`${this._gridMinH}px`,s.classList.add("opacity-0","pointer-events-none"),s.setAttribute("aria-hidden","true"),this.buttonTargets?.forEach(a=>a.setAttribute("disabled","disabled")),this.layoutButtonTargets?.forEach(a=>a.setAttribute("disabled","disabled")),this.hasPagyNavTarget&&this.pagyNavTarget.classList.add("pointer-events-none","opacity-60")}stopLoading(){let a=performance.now()-(this._loadingAt||0),t=Math.max(0,150-a);window.setTimeout(()=>{let e=this.productsGridTarget;e.classList.remove("opacity-0","pointer-events-none"),e.removeAttribute("aria-hidden"),e.style.minHeight="",this.hasSpinnerTarget&&this.spinnerTarget.classList.add("hidden"),this.buttonTargets?.forEach(o=>o.removeAttribute("disabled")),this.layoutButtonTargets?.forEach(o=>o.removeAttribute("disabled")),this.hasPagyNavTarget&&this.pagyNavTarget.classList.remove("pointer-events-none","opacity-60")},t)}};export{l as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.