1class o extends window.HTMLElement{constructor(){super(),this.storageKey="sn_recently_viewed",this.maxProducts=12}connectedCallback(){const e=this.dataset.currentProductHandle;e&&(this.saveProduct(e),console.log("Saved product:",e)),this.loadRecentlyViewed()}saveProduct(e){try{let t=this.getRecentlyViewed();t=t.filter(r=>r!==e),t.unshift(e),t=t.slice(0,this.maxProducts),localStorage.setItem(this.storageKey,JSON.stringify(t)),console.log("Recently viewed updated:",t)}catch(t){console.error("Failed to save recently viewed product:",t)}}getRecentlyViewed(){try{const e=localStorage.getItem(this.storageKey);if(!e)return[];const t=JSON.parse(e);return t.every(s=>typeof s=="string"&&isNaN(s))?t:(console.log("Clearing old recently viewed data format"),localStorage.removeItem(this.storageKey),[])}catch(e){return console.error("Failed to get recently viewed products:",e),[]}}async loadRecentlyViewed(){const e=this.dataset.currentProductHandle,t=parseInt(this.dataset.limit)||8;let r=this.getRecentlyViewed();if(console.log("Loading recently viewed:",r),e&&(r=r.filter(s=>s!==e)),r=r.slice(0,t),r.length===0){console.log("No recently viewed products"),this.hideSection();return}try{const s=await this.fetchProducts(r);console.log("Fetched products:",s),s.length>0?(this.renderProducts(s),this.classList.add("loaded")):this.hideSection()}catch(s){console.error("Failed to load recently viewed products:",s),this.hideSection()}}hideSection(){const e=this.closest(".recently-viewed-section");e?e.style.display="none":this.style.display="none"}async fetchProducts(e){const t=[];for(const r of e)try{const s=await fetch(`${window.Shopify.routes.root}products/${r}.js`);if(s.ok){const i=await s.json();t.push(i)}else console.error(`Failed to fetch product ${r}: ${s.status}`)}catch(s){console.error(`Failed to fetch product ${r}:`,s)}return t}renderProducts(e){const t=this.dataset.gap||"1.5rem",s=` 2 <section class='featured-reviews lg:py-16 py-12'> 3 <div class='featured-reviews-container'> 4 <div class='md:px-8 px-4 mb-8'> 5 <h2 class='text-3xl lg:text-5xl font-serif underline text-center'> 6 ${this.dataset.title||"Recently Viewed"} 7 </h2> 8 </div> 9 <div class='reviews-container relative'> 10 <div class='carousel-scroll overflow-x-auto scrollbar-hide pr-gutter-page'> 11 <div class='carousel-container flex md:px-8 px-4 pt-4' style='--gap: ${t}; gap: ${t};'> 12 ${e.map(i=>this.renderProductCard(i)).join("")} 13 </div> 14 </div> 15 </div> 16 </div> 17 </section> 18 `;this.innerHTML=s}renderProductCard(e){const t=(e.price/100).toFixed(2),r=e.compare_at_price?(e.compare_at_price/100).toFixed(2):null,s=e.featured_image||e.images[0];return` 19 <div class='product-card w-full lg:w-80 flex-shrink-0'> 20 <a href='${e.url}' class='product-card-link block'> 21 <div class='product-card-image aspect-square mb-4 image relative overflow-hidden'> 22 ${s?`<img 23 src='${s}' 24 alt='${e.title}' 25 class='absolute inset-0 w-full h-full object-cover' 26 loading='lazy' 27 />`:"<div class='w-full h-full bg-light-green'></div>"} 28 </div> 29 <div class='product-card-info'> 30 <h2 class='font-serif text-2xl lg:text-4xl lg:text-left text-center underline'> 31 ${e.title} 32 </h2> 33 <div class='flex gap-2 items-center mt-2 lg:justify-start justify-center'> 34 <span class='text-lg font-serif'>$${t}</span> 35 ${r?`<span class='text-sm font-serif line-through opacity-60'>$${r}</span>`:""} 36 </div> 37 </div> 38 </a> 39 </div> 40 `}}window.customElements.define("recently-viewed",o);export{o as default}; 41//# sourceMappingURL=/cdn/shop/t/148/assets/recently-viewed-8O8trNkq.js.map
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.