1import{b as o,c as u,e as h}from"./chunk-UWFWQZHK.js";var l,d=h(()=>{l=class extends HTMLElement{constructor(){super(),this.carousel=null,this.uuid=null,this.apiKey=null,this.dataSourceId=null,this.parameters={limit:12,metafields:"no",variant_metafields:"no"},this.minimumProducts=1,this.productView="card",this.selectors={carousel:"[js-carousel]",wrapper:".swiper-wrapper",quickAddModal:"quickadd-modal",skeleton:"[data-rebuy-skeleton]",content:"[data-rebuy-content]"},this.setupConfig(),this.init()}setupConfig(){this.uuid=this.getRebuyUUID(),this.apiKey=this.dataset.apiKey,this.dataSourceId=this.dataset.dataSourceId,this.parameters=u(o(o({},this.parameters),JSON.parse(this.dataset.parameters)),{url:encodeURIComponent(window.location.href)}),this.minimumProducts=parseInt(this.dataset.minimumProducts)||1,this.productView=this.dataset.productView,this.carousel=this.querySelector(this.selectors.carousel)}getCookie(e){let i=`; ${document.cookie}`.split(`; ${e}=`);return i.length===2?i.pop().split(";").shift():null}getRebuyUUID(){let e=this.getCookie("_ruid");if(e!==null){let t=atob(decodeURIComponent(e));return JSON.parse(t).uuid}return null}getProducts(){return fetch(`https://rebuyengine.com/api/v1/custom/id/${this.dataSourceId}?key=${this.apiKey}&uuid=${this.uuid}&${new URLSearchParams(this.parameters).toString()}`).then(e=>e.json()).then(e=>{let t=e==null?void 0:e.data;return Array.isArray(t)?t:t&&Array.isArray(t.products)?t.products:[]}).catch(e=>(console.error("Error fetching products:",e),[]))}getSlideHtml(e){return e?`<div class="swiper-slide" role="group" aria-roledescription="slide" js-carousel-slide>${e}</div>`:""}getProductCard(e){let t=(e==null?void 0:e.handle)||(e==null?void 0:e.shopify_handle);return t?fetch(`/products/${encodeURIComponent(t)}?view=${this.productView}`).then(i=>i.ok?i.text():(console.error(`Error fetching product card for ${t}: ${i.status}`),"")).catch(i=>(console.error("Error rendering server card:",i),"")):Promise.resolve("")}reinitializeComponents(){var e,t;(e=segmentTracker==null?void 0:segmentTracker.productCardTracker)==null||e.reinitialize(),(t=document.querySelector(this.selectors.quickAddModal))==null||t.reinit()}hideSkeleton(){var e;(e=this.querySelector(this.selectors.skeleton))==null||e.remove()}reveal(){var e;(e=this.querySelector(this.selectors.content))==null||e.removeAttribute("hidden"),this.classList.remove("invisible"),this.hasAttribute("hidden")&&this.removeAttribute("hidden")}refreshCarousel(){var i,s;let e=this.querySelector("theme-carousel"),t=this.carousel&&this.carousel.swiper||e&&e.carousel;t&&typeof t.update=="function"&&(t.update(),(s=(i=t.navigation)==null?void 0:i.update)==null||s.call(i))}init(){if(this.carousel,!this.carousel){this.hideSkeleton();return}this.getProducts().then(e=>{if(!Array.isArray(e)||!e.length){this.hideSkeleton();return}if(this.minimumProducts&&e.length<this.minimumProducts){this.hideSkeleton();return}let t=e.map(i=>this.getProductCard(i));Promise.allSettled(t).then(i=>{let a=i.filter(r=>r.status==="fulfilled"&&r.value&&r.value.trim()).map(r=>r.value).map(r=>this.getSlideHtml(r)).filter(r=>r.trim()),n=this.carousel.querySelector(this.selectors.wrapper);n&&a.length>=this.minimumProducts?customElements.whenDefined("theme-carousel").then(()=>{requestAnimationFrame(()=>{this.hideSkeleton(),n.innerHTML=a.join(""),this.reveal(),this.refreshCarousel(),this.reinitializeComponents()})}):this.hideSkeleton()})})}}});d();export{l as RebuyCollection};
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.