import{r as e,c as t,h as i,H as n}from"./p-567d4700.js";import{K as o}from"./p-5d8b1fbd.js";import{p as r}from"./p-278e49c3.js";import{c as d,K as s,b as a}from"./p-d0bfb1d8.js";import{k as u}from"./p-6dcbd18c.js";import"./p-c55c67b2.js";import"./p-97d1323d.js";import"./p-c2e91ee8.js";import"./p-cad738c9.js";const c=[s.AlsoBought,s.AlsoViewed,s.NewArrivals,s.SimilarProducts,s.Trending];function l(e,t,i){return{klevuModifierId:"sendMerchandisingViewEvent",onResult:(n,o)=>{var r,s,a,u,l,f,v,h,m;if(o.klevuFunctionId==="kmcRecommendation"){if(!e){e=(a=(s=(r=o.params)===null||r===void 0?void 0:r.kmcConfig)===null||s===void 0?void 0:s.metadata.title)!==null&&a!==void 0?a:""}const t=(f=n.queriesById((l=(u=o.queries)===null||u===void 0?void 0:u[0].id)!==null&&l!==void 0?l:""))===null||f===void 0?void 0:f.records;if(!t){console.warn("No result in recommendations. Can't send recommendationViewEvent");return n}const c=(v=o.params)===null||v===void 0?void 0:v.kmcConfig;if(!c){console.warn("Problem with kmcData fetching. Can't send recommendationViewEvent");return n}if(t.length===0){return n}d.recommendationView({recommendationMetadata:Object.assign(Object.assign({},c.metadata),{title:e}),products:t,override:i});return n}if(!t){throw new Error("Need to provider eventData parameter for custom view events")}const p=(h=o.queries)===null||h===void 0?void 0:h.filter((e=>c.includes(e.typeOfRequest)));if(!p||(p===null||p===void 0?void 0:p.length)==0){return n}const w=(m=n.queriesById(p[0].id))===null||m===void 0?void 0:m.records;if(!w){console.warn("No products in result. Can't send recommendationViewEvent");return n}t.title=e!==null&&e!==void 0?e:t.title;d.recommendationView({recommendationMetadata:t,products:w});return n}}}const f=":host{display:block}";var v=undefined&&undefined.__classPrivateFieldSet||function(e,t,i,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t==="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(e,i):o?o.value=i:t.set(e,i),i};var h=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;const p=class{constructor(i){e(this,i);this.klevuData=t(this,"klevuData",7);m.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]}async connectedCallback(){var e,t;await o.ready();if(!this.recommendationId){throw new Error("recommendationId is required")}const i=await a(u(this.recommendationId,{id:"recommendation",cartProductIds:this.cartProductIds,categoryPath:this.categoryPath,currentProductId:this.currentProductId,itemGroupId:this.itemGroupId},l(this.recommendationTitle)));v(this,m,i.queriesById("recommendation"),"f");if(h(this,m,"f")){if(this.recommendationTitle===undefined){this.recommendationTitle=(t=(e=h(this,m,"f").getQueryParameters())===null||e===void 0?void 0:e.kmcConfig)===null||t===void 0?void 0:t.metadata.title}this.products=h(this,m,"f").records;this.klevuData.emit(h(this,m,"f"))}}productClick(e){var t,i;if(((t=h(this,m,"f"))===null||t===void 0?void 0:t.recommendationClickEvent)&&e.detail.product.id){(i=h(this,m,"f"))===null||i===void 0?void 0:i.recommendationClickEvent({productId:e.detail.product.id,variantId:e.detail.product.itemGroupId||e.detail.product.id})}}render(){if(this.products.length===0){return null}return i(n,null,i("slot",null,i("klevu-slides",{heading:this.recommendationTitle},this.products.map((e=>i("klevu-product",{exportparts:r["klevu-product"],fixedWidth:true,product:e,style:{"--klevu-product-width":"300px"}}))))))}};m=new WeakMap;p.style=f;export{p as klevu_recommendations};
//# sourceMappingURL=p-bc9202fb.entry.js.map