1import{d as _}from"./theme.BUvWqrRt.min.js";const w="octane_quiz_results_gz";async function b(r){const t=atob(r),e=new Uint8Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);const n=new Blob([e]).stream().pipeThrough(new DecompressionStream("gzip"));return new Response(n).text()}async function m(){try{const r=sessionStorage.getItem(w);if(r)return await b(r)}catch{}return null}const C=_(r=>({loading:!0,hasResults:!1,sections:[],quizData:null,config:{sliderSectionId:r.sliderSectionId||"quiz-product-card",maxCards:r.maxCards??10},init(){this.loadQuizResults()},async loadQuizResults(){this.loading=!0;let t=await m();if(t||(await new Promise(n=>setTimeout(n,300)),t=await m()),!t){this.loading=!1,this.hasResults=!1;return}try{this.quizData=JSON.parse(t)}catch{this.loading=!1,this.hasResults=!1;return}const e=this.buildSections();if(e.length===0){this.loading=!1,this.hasResults=!1;return}this.hasResults=!0,this.sections=e,this.loading=!1,await this.$nextTick();for(let n=0;n<this.sections.length;n++)this.sections[n].type==="products"&&await this.loadSlider(n)},limitHandles(t){const e=this.config.maxCards;return e>0&&t.length>e?t.slice(0,e):t},buildSections(){var t;return this.quizData?(t=this.quizData.sections)!=null&&t.length?this.quizData.sections.filter(e=>{const n=e.products&&e.products.length>0,i=e.top_content&&e.top_content.length>0||e.bottom_content&&e.bottom_content.length>0;return n||i}).map(e=>{const n=this.limitHandles(this.extractHandles(e.products||[])),i=this.getSectionTitleBlockId(e);return{id:e.id,type:n.length>0?"products":"text",title:this.getSectionTitle(e),topContent:this.extractContent(e.top_content,i),bottomContent:this.extractContent(e.bottom_content),handles:n,loading:n.length>0}}):[]:[]},extractContent(t,e){return t?t.filter(n=>!e||n.content_id!==e).map(n=>this.renderContentBlock(n)).filter(n=>n.length>0):[]},escapeAttr(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")},renderContentBlock(t){switch(t.content_type){case"image":{if(!t.url)return"";const e=this.escapeAttr(t.alt_text||""),n=t.max_width?`max-width:${t.max_width}px;`:"",i=`<img src="${t.url}" alt="${e}" style="${n}width:100%;height:auto;" loading="lazy">`;return`<div style="display:flex;justify-content:center;">${t.href_url?`<a href="${t.href_url}">${i}</a>`:i}</div>`}case"button":{if(!t.url||!t.text)return"";const e=t.open_link_same_tab?"":' target="_blank" rel="noopener"',n=t.type==="secondary"?"button button--secondary":"button button--primary",i=t.size==="small"?" button--small":t.size==="large"?" button--large":"";return`<div style="display:flex;justify-content:center;"><a href="${t.url}" class="${n}${i}"${e}>${t.text}</a></div>`}case"text":{if(!t.text)return"";let e="p";return t.text_type==="title"||t.text_type==="heading"?e="h2":t.text_type==="subheading"?e="h3":t.text_type==="caption"&&(e="small"),`<${e}>${t.text}</${e}>`}case"video":return t.url?`<div style="${t.max_width?`max-width:${t.max_width}px;`:""}width:100%;"><div style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;"><iframe src="${t.url}" style="position:absolute;top:0;left:0;width:100%;height:100%;border:0;" allowfullscreen loading="lazy"></iframe></div></div>`:"";case"html":return t.html||"";case"url":{if(!t.url)return"";const e=t.text||t.url;return`<a href="${t.url}">${e}</a>`}default:return(t.rich_editor||t.text||"").trim()}},getSectionTitleBlockId(t){if(t.top_content){const e=t.top_content.find(n=>n.text_type==="title"||n.text_type==="heading");if(e&&(e.rich_editor||e.text))return e.content_id}},getSectionTitle(t){if(t.top_content){const e=t.top_content.find(n=>n.text_type==="title"||n.text_type==="heading");if(e)return e.rich_editor||e.text||""}return t.name||""},extractHandles(t){const e=new Set;return t.map(n=>{if(!n.link)return null;const i=n.link.match(/\/products\/([^/?#]+)/);return i?i[1]:null}).filter(n=>n===null||e.has(n)?!1:(e.add(n),!0))},async loadSlider(t){const e=this.sections[t];if(!e)return;if(e.handles.length===0){e.loading=!1;return}const n=document.getElementById(`quiz-results-section-${t}`);if(!n){e.loading=!1;return}const i=this.config.sliderSectionId.replace(/_/g,"-"),s=[],g=e.handles.map(async o=>{const x=`${window.Shopify.routes.root}products/${o}?sections=${i}`;try{const f=await fetch(x);if(!f.ok)return null;const a=await f.json(),u=a[i]||a[Object.keys(a)[0]];if(u&&u.trim().length>0){const p=new DOMParser().parseFromString(u,"text/html").querySelector("[data-quiz-product-card]");return p?p.outerHTML:null}return null}catch{return null}}),y=await Promise.all(g);for(const o of y)o&&s.push(o);if(s.length===0){e.loading=!1;return}const c=document.getElementById("quiz-slider-template");if(!c){e.loading=!1;return}const l=c.content.cloneNode(!0),d=l.querySelector("tile-slider");d&&d.setAttribute("x-data",`tileSlider({ totalSlides: ${s.length} })`);
1const h=l.querySelector("[data-slider-track]");h&&(h.innerHTML=s.join(` 2`)),n.innerHTML="",n.appendChild(l),this.reinitializeCustomElements(n),window.Alpine&&window.Alpine.initTree(n),e.loading=!1},reinitializeCustomElements(t){t.querySelectorAll("tile-slider, quick-add-modal, modal-opener, product-form").forEach(e=>{var i;const n=e.cloneNode(!0);(i=e.parentNode)==null||i.replaceChild(n,e)})}}));export{C 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.