1"use strict";(globalThis.webpackChunkNorden_Commerce=globalThis.webpackChunkNorden_Commerce||[]).push([[4540],{752(e,t,r){r.d(t,{productfinderInit:()=>o});var s=r(4310),a=r(6540),i=r(5338),c=r(4561),n=r(4504);class d extends a.Component{constructor(e){super(e),this.descriptionEnabled=!0,this.root=e.root,this.baseUrl=`/api/v2/productfinder/${e.id}/`,this.id=e.id,this.submitOnChange=!1,this.scrollY=window.scrollY,this.state={initial_data:!1,loading:!0,breadcrumb:[],answer:null,step:0,selected_attributes:[]}}componentDidMount(){(0,n.Mm)("[data-productfinder]",{target:"[data-description]",theme:"light",allowHTML:!0,interactive:!0,trigger:"click",maxWidth:400,content:e=>e.getAttribute("data-description"),onShown:e=>{let t;const r=e.reference,s=e.popper.querySelector(".c-productfinder__choice-description-close"),a=e.popper.querySelector("[data-litebox]"),i=[r,s,a];function c(r){if("Tab"===r.key){r.preventDefault();const e=document.activeElement;let t=(i.indexOf(e)+(r.shiftKey?-1:1)+i.length)%i.length;i[t]?.focus()}else"Escape"===r.key&&(r.preventDefault(),t||e.hide())}r.setAttribute("aria-expanded",!0),r.querySelector("span").textContent=`${gettext("less info")}`,s.addEventListener("click",()=>e.hide()),document.addEventListener("Litebox:afteropen",e=>{t=!0}),document.addEventListener("Litebox:afterclose",e=>{t=!1}),e._removeTabHandler=()=>r.ownerDocument.removeEventListener("keydown",c),r.ownerDocument.addEventListener("keydown",c)},onHide(e){const t=e.reference;e._removeTabHandler?.(),e.reference.focus(),t.setAttribute("aria-expanded",!1),t.querySelector("span").textContent=`${gettext("more info")}`}});const e=window.history.state;if(e?.productfinder&&e.productfinder.findIndex(e=>e.id===this.id)>=0){const t=e.productfinder.filter(e=>e.id===this.id)[0];this.setState({initial_data:!0,step:t.step,breadcrumb:t.breadcrumb,question:t.question,answer:t.answer,result:t.result,selected_attributes:t.selected_attributes,complete:!t.question,loading:!1},()=>{this.state.question&&this.handleQuestion(t.question.slug),this.handleInitialize(),this.root.querySelector("[data-productfinder-loader]").style.display="none",s.P.emit("Productfinder:updated")})}else(0,c.Fp)(`${this.baseUrl}reset/`,{method:"GET"}).then(e=>{this.handleInitialize()});window.addEventListener("popstate",e=>{const t=e.state?.productfinder?.step||0;this.handleBreadcrumb(t),this.setState({step:Math.min(Math.max(t-1,0))})})}handleInitialize(){this.handleScroll(),this.root.querySelector("[data-productfinder-loader]").style.display="block",this.state.initial_data?this.setState({loading:!1}):(this.setState({loading:!0,breadcrumb:[],answer:null,step:0,complete:!1,selected_attributes:[]}),(0,c.Fp)(`${this.baseUrl}`).then(e=>{let{breadcrumb:t}=this.state;0===t.length&&t.push({question:e.start_question,slug:e.slug,step_name:e.start_question.step_name,text:e.text}),this.setState({loading:!1,name:e.name,description:e.description,question:e.start_question,prev_question:null},()=>{this.root.querySelector("[data-productfinder-loader]").style.display="none",s.P.emit("Productfinder:updated")})}).catch(e=>console.error(e)))}handleQuestion(e){const t=`?slice_index=${this.state.step}`;(0,c.Fp)(`${this.baseUrl}question/${e}/${t}`).then(e=>{this.setState({complete:!1},()=>{let e=this.state.breadcrumb[this.state.step].prev_answer;if(e||(e=this.state.answer),e){const t=this.root.querySelector(`#answer__${this.id}__${e.slug}`);t&&(t.checked="checked"),this.handleAnswer(e)}s.P.emit("Productfinder:updated")})})}handleAnswer(e,t){this.setState({answer:e},()=>{this.handleHistory()}),(0,c.Fp)(`${this.baseUrl}submit/${e.slug}/`,{method:"GET"}).then(e=>{this.setState({last_question:!e.next_question,result:e.result}),this.handleHistory()}),this.submitOnChange&&"radio"===t&&this.handleSubmit(e.slug)}updateDatalayer(e){const t=e?.result?.products?.map(e=>e.identifiers.sku)||[];window.dataLayer=window.dataLayer||[];const r={event:"used_product_finder",matched_skus:t};window._mtm=window._mtm||[],window._mtm.push(r),window.dataLayer.push(r)}handleSubmit(e){e||(e=this.state.answer.slug),(0,c.Fp)(`${this.baseUrl}submit/${e}/`,{method:"GET"}).then(e=>{this.scrollY=window.scrollY;let{selected_attributes:t,breadcrumb:r}=this.state;if(r[this.state.step].prev_answer=e,r.push({question:e.next_question,slug:e.slug,step_name:e.next_question?.step_name||ngettext("Result","Results",1),text:e.next_question?e.text:e.result.count}),e.associated_object&&e.associated_object.attribute){const r=t.findIndex(t=>t.attribute.name===e.associated_object.attribute.name);r>=0?(t.splice(r,1),t.splice(r,0,e.associated_object)):t.push(e.associated_object)}this.updateDatalayer(e),this.setState({breadcrumb:r,current_question:e.question,question:e.next_question,result:e.result,complete:!e.next_question,answer:null,answer_results:e.next_question?.answers.some(e=>e.count>0),step:this.state.step+1,prev_question:this.state.question,selected_attributes:t},()=>{this.state.complete?this.root.querySelector(".c-productfinder__result a")?.focus():this.root.querySelector(".c-productfinder__choices input")?.focus(),this.handleHistory(e),s.P.emit("Productfinder:updated")})}).catch(e=>console.error(e))}handleHistory(e){const t=new URL(location),r=history.state?.productfinder||[];if(r.length>0){if(r.filter(e=>e.id===this.id).length>0){const e=r.findIndex(e=>e.id===this.id);r.splice(e,1)}}r.push({id:this.id,step:this.state.step,question:this.state.question,result:this.state.result,answer:this.state.answer,breadcrumb:this.state.breadcrumb,selected_attributes:this.state.selected_attributes}),history.pushState({productfinder:r},"",t)}handleBreadcrumb(e){e!==this.state.step&&(this.state.breadcrumb.splice(e+1,this.state.breadcrumb.length),this.setState({initial_data:!1,step:e,breadcrumb:this.state.breadcrumb,last_question:!1,question:this.state.breadcrumb[e].question},()=>{this.handleQuestion(this.state.breadcrumb[e].question.slug),s.P.emit("Productfinder:updated")}),this.handleScroll())}handleScroll(){window.scrollY>this.scrollY&&window.scrollTo({top:this.scrollY,left:0,behavior:"smooth"})}handleRestart(){const e=new URL(location);e.searchParams.delete("step"),e.searchParams.delete("pid"),e.searchParams.delete("qid"),e.searchParams.delete("aid"),history.pushState({},"",e),(0,c.Fp)(`${this.baseUrl}reset/`,{method:"GET"}).then(e=>{this.setState({initial_data:!1},()=>this.handleInitialize())})}handleBack(){const e=this.state.step-1;this.handleBreadcrumb(e)}render(){const{breadcrumb:e,name:t,description:r,question:s,result:i,loading:c,complete:n,selected_attributes:d,step:o,answer:l,last_question:u}=this.state,p=e=>`<button class="c-productfinder__choice-description-close" aria-label="${gettext("Close")}"></button>`+(e.description?`<p class="c-productfinder__choice-description-text">${e.description}</p>`:"")+(e.description_image?`<a data-litebox href="${e.description_image}"><img class="c-productfinder__choice-description-image" src="${e.description_image}" alt=""></a><span class="c-productfinder__choice-description-zoom">${gettext("Click image for zoom")}</span>`:"");return a.createElement(a.Fragment,null,!c&&a.createElement(a.Fragment,null,a.createElement("div",{className:"c-productfinder__breadcrumb"},a.createElement("p",{className:"c-productfinder__breadcrumb-item c-productfinder__breadcrumb-item--restart",onClick:()=>this.handleRestart()},gettext("Restart")),e.map((e,t)=>a.createElement("p",{key:e.question?.slug||e.slug,className:"c-productfinder__breadcrumb-item",onClick:()=>this.handleBreadcrumb(t)},e.step_name,e.prev_answer&&a.createElement("span",{className:"c-productfinder__breadcrumb-item-answer"},e.prev_answer.text)))),!n&&a.createElement("div",{className:"c-productfinder__question-container"},a.createElement("div",{className:"c-productfinder__question"},s.text),a.createElement("div",{className:"c-productfinder__choices"},s.answers.map((e,t)=>a.createElement("div",{key:e.slug,className:`c-productfinder__choice ${e.image?"c-productfinder__choice--image":""} ${0===e.count?"is-disabled":""}`,"data-choice-type":s.type?s.type:"radio"},a.createElement("input",{id:`answer__${this.id}__${e.slug}`,className:"c-productfinder__choice-input",type:s.type?s.type:"radio",name:s.slug,value:e.text,disabled:0===e.count,onChange:()=>this.handleAnswer(e,s.type?s.type:"radio")}),a.createElement("label",{htmlFor:`answer__${this.id}__${e.slug}`,className:"c-productfinder__choice-label"},e.image&&a.createElement("img",{className:"c-productfinder__choice-image",src:e.image,alt:""}),a.createElement("div",{className:"c-productfinder__choice-option","aria-label":`${e.text} - ${e.count} ${ngettext("Result","Results",e.count)}`,"data-count":e.count,"data-count-text":`${ngettext("Result","Results",e.count)}`},a.createElement("span",{className:"c-productfinder__choice-text"},e.text))),this.descriptionEnabled&&(e.description||e.description_image)&&a.createElement("button",{className:"c-productfinder__choice-description","aria-expanded":"false","data-description":p(e)},a.createElement("span",null,`${gettext("more info")}
1`)))))),n&&a.createElement("div",{className:"c-productfinder__result"},a.createElement("p",{className:"c-productfinder__result-title"},`${ngettext("We found the following product for you","We found the following products for you",i.count)}`,":"),a.createElement("div",{className:"c-productfinder__products"},i.products.map(e=>a.createElement("div",{key:e.identifiers.product_id,className:"c-productfinder__product"},a.createElement("div",{className:"c-productfinder__product-image"},a.createElement("a",{href:e.url},a.createElement("img",{src:e.main_image.thumbnail,alt:"",width:"400"})),e.flags&&a.createElement("div",{className:"c-productfinder__product-flags",dangerouslySetInnerHTML:{__html:e.flags.html}})),a.createElement("div",{className:"c-productfinder__product-infos"},a.createElement("p",{className:"c-productfinder__product-title"},e.descriptions.title),a.createElement("p",{className:"c-productfinder__product-subtitle"},e.descriptions.subtitle),d.length>0&&a.createElement("div",{className:"c-productfinder__product-attributes"},d.map(e=>a.createElement("div",{key:e.slug,className:"c-productfinder__product-attribute"},a.createElement("span",{className:"c-productfinder__product-attribute__attribute"},e.attribute.description,":"),a.createElement("span",{className:"c-productfinder__product-attribute__value"},e.value_with_unit)))),a.createElement("div",{className:"c-productfinder__product-price"},e.direct_cashback?a.createElement(a.Fragment,null,a.createElement("div",{className:"c-productfinder__product-price-direct-cashback-wrapper"},a.createElement("p",{className:"c-productfinder__product-price__price c-productfinder__product-price__price--old-price"},a.createElement("span",{dangerouslySetInnerHTML:{__html:e.offer.formatted_price.normal_price_formatted}}),a.createElement("sup",null,"*")),a.createElement("p",{className:"c-productfinder__product-price__price c-productfinder__product-price__price--sale-price c-productfinder__product-price__price--special-with-cashback"},a.createElement("span",{dangerouslySetInnerHTML:{__html:e.offer.formatted_price.special_price_formatted}}),a.createElement("sup",null,"*"),a.createElement("span",null,Hatraco.i18n.afterCashback))),a.createElement("div",{className:"c-productfinder__product-direct-cashback",dangerouslySetInnerHTML:{__html:e.direct_cashback}})):a.createElement(a.Fragment,null,e.offer.formatted_price.is_special_offer&&a.createElement("p",{className:"c-productfinder__product-price__price c-productfinder__product-price__price--old-price"},a.createElement("span",{dangerouslySetInnerHTML:{__html:e.offer.formatted_price.normal_price_formatted}}),a.createElement("sup",null,"*")),a.createElement("p",{className:"c-productfinder__product-price__price c-productfinder__product-price__price--sale-price"},a.createElement("span",{dangerouslySetInnerHTML:{__html:e.offer.formatted_price.sale_price_formatted}}),a.createElement("sup",null,"*")))),a.createElement("a",{href:e.url,className:"c-productfinder__product-cta"},`${gettext("Show product")}`)))))),a.createElement("div",{className:"c-productfinder__controls","data-productfinder-controls":!0},o>0&&a.createElement("button",{className:"c-productfinder__control c-productfinder__control--back","data-productfinder-previous":!0,onClick:()=>this.handleBack()},`${gettext("Previous")}`),!n&&a.createElement("button",{className:"c-productfinder__control c-productfinder__control--next "+(l?"":"is-disabled"),"data-productfinder-next":!0,onClick:()=>this.handleSubmit()},`${u?ngettext("Result","Results",i.count):gettext("Next")}`))))}}const o=()=>{const e=document.querySelectorAll("[data-productfinder]");if(e)for(const t of e){const e=t.getAttribute("data-productfinder");(0,i.createRoot)(t.querySelector("[data-productfinder-body]")).render(a.createElement(d,{root:t,id:e}))}}}}]);
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.