import{r as e,h as t,H as i}from"./p-23359d3b.js";import{K as n}from"./p-b56c314a.js";import{p as r}from"./p-98c3fe1e.js";import{b as o,c as d,K as s}from"./p-8db0d257.js";import{k as a}from"./p-ee4a57fa.js";import"./p-52fee6fd.js";import"./p-97d1323d.js";const u=[d.AlsoBought,d.AlsoViewed,d.NewArrivals,d.SimilarProducts,d.Trending];function c(e,t,i){return{klevuModifierId:"sendMerchandisingViewEvent",onResult:(n,r)=>{var d,s,a,c,f,h;if(r.klevuFunctionId==="kmcRecommendation"){const t=(a=n.queriesById((s=(d=r.queries)===null||d===void 0?void 0:d[0].id)!==null&&s!==void 0?s:""))===null||a===void 0?void 0:a.records;if(!t){console.warn("No result in recommendations. Can't send recommendationViewEvent");return n}const u=(c=r.params)===null||c===void 0?void 0:c.kmcConfig;if(!u){console.warn("Problem with kmcData fetching. Can't send recommendationViewEvent");return n}if(t.length===0){return n}o.recommendationView({recommendationMetadata:Object.assign(Object.assign({},u.metadata),{title:e}),products:t,override:i});return n}if(!t){throw new Error("Need to provider eventData parameter for custom view events")}const l=(f=r.queries)===null||f===void 0?void 0:f.filter((e=>u.includes(e.typeOfRequest)));if(!l||(l===null||l===void 0?void 0:l.length)==0){return n}const m=(h=n.queriesById(l[0].id))===null||h===void 0?void 0:h.records;if(!m){console.warn("No products in result. Can't send recommendationViewEvent");return n}o.recommendationView({recommendationMetadata:Object.assign(Object.assign({},t),{title:e}),products:m});return n}}}const f=":host{display:block}";var h=undefined&&undefined.__classPrivateFieldSet||function(e,t,i,n,r){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t==="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?r.call(e,i):r?r.value=i:t.set(e,i),i};var l=undefined&&undefined.__classPrivateFieldGet||function(e,t,i,n){if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t==="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?n:i==="a"?n.call(e):n?n.value:t.get(e)};var m,v,p,w;const b=class{constructor(t){e(this,t);m.add(this);v.set(this,void 0);this.recommendationTitle=undefined;this.recommendationId=undefined;this.cartProductIds=undefined;this.categoryPath=undefined;this.currentProductId=undefined;this.itemGroupId=undefined;this.products=[undefined,undefined,undefined,undefined,undefined,undefined];this.renderProductSlot=undefined}async connectedCallback(){await n.ready();if(!this.recommendationId){throw new Error("recommendationId is required")}const e=await s(a(this.recommendationId,{id:"recommendation",cartProductIds:this.cartProductIds,categoryPath:this.categoryPath,currentProductId:this.currentProductId,itemGroupId:this.itemGroupId},c(this.recommendationTitle)));h(this,v,e.queriesById("recommendation"),"f");if(l(this,v,"f")){this.products=l(this,v,"f").records}}render(){if(this.products.length===0){return null}return t(i,null,t("klevu-slides",{heading:this.recommendationTitle},this.products.map((e=>t("klevu-product",{exportparts:r["klevu-product"],fixedWidth:true,onKlevuProductClick:l(this,m,"m",w).bind(this),product:e,style:{"--klevu-product-width":"300px"}},l(this,m,"m",p).call(this,e,"top"),l(this,m,"m",p).call(this,e,"image"),l(this,m,"m",p).call(this,e,"info"),l(this,m,"m",p).call(this,e,"bottom"))))))}};v=new WeakMap,m=new WeakSet,p=function e(i,n){if(!this.renderProductSlot||!i){return null}const r=this.renderProductSlot(i,n);if(r===null){return null}if(typeof r==="string"){return t("div",{slot:n,innerHTML:r})}return t("div",{slot:n,ref:e=>{if(!e){return}e.innerHTML="";e.appendChild(r)}})},w=function e(t){var i,n;if(((i=l(this,v,"f"))===null||i===void 0?void 0:i.recommendationClickEvent)&&t.detail.product.id){(n=l(this,v,"f"))===null||n===void 0?void 0:n.recommendationClickEvent({productId:t.detail.product.id,variantId:t.detail.product.itemGroupId||t.detail.product.id})}};b.style=f;export{b as klevu_recommendations};
//# sourceMappingURL=p-c1fa59e5.entry.js.map