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