import{r as e,c as t,h as r,H as i}from"./p-e81f56ed.js";import{K as s}from"./p-71f4cbd4.js";import{F as o}from"./p-e88ac86e.js";import{b as n,a}from"./p-06444484.js";import{K as h,a as d}from"./p-1b562ffa.js";import{s as c}from"./p-6b11a3a7.js";import{k as f}from"./p-57c7f607.js";import{c as u,s as l}from"./p-33229f10.js";import{l as m}from"./p-1300edbf.js";import{s as p}from"./p-b7c74937.js";import"./p-e66456dc.js";var w=undefined&&undefined.__classPrivateFieldGet||function(e,t,r,i){if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t==="function"?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?i:r==="a"?i.call(e):i?i.value:t.get(e)};var y=undefined&&undefined.__classPrivateFieldSet||function(e,t,r,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof t==="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(e,r):s?s.value=r:t.set(e,r),r};var v,g,C,b;const k=class{constructor(r){e(this,r);this.klevuQueryResult=t(this,"klevuQueryResult",7);v.add(this);g.set(this,void 0);C.set(this,void 0);this.type=undefined;this.sendSearchViewEvent=undefined;this.options=undefined;this.sort=undefined;this.limit=undefined;this.offset=undefined;this.filterCount=undefined;this.category=undefined;this.categoryTitle=undefined;this.searchTerm=undefined;this.recommendationId=undefined;this.manager=new o;this.updateOnFilterChange=undefined}onPropertyChange(){this.fetchAgain()}async fetchAgain(){await w(this,v,"m",b).call(this)}async connectedCallback(){await s.ready();await w(this,v,"m",b).call(this);if(this.updateOnFilterChange){y(this,g,n(a.FilterSelectionUpdate,(async()=>{await w(this,v,"m",b).call(this)})),"f")}}disconnectedCallback(){if(w(this,g,"f")){w(this,g,"f").call(this)}}onProductClick(e){var t,r,i,s,o,n;const a=e.detail.product;if(!w(this,C,"f")||!a.id){return}switch(this.type){case"merchandising":if(this.categoryTitle){(r=(t=w(this,C,"f")).getCategoryMerchandisingClickSendEvent)===null||r===void 0?void 0:r.call(t)(a.id,this.categoryTitle,a.itemGroupId)}break;case"recommendation":(s=(i=w(this,C,"f")).getRecommendationClickSendEvent)===null||s===void 0?void 0:s.call(i)(a.id,a.itemGroupId);break;case"search":(n=(o=w(this,C,"f")).getSearchClickSendEvent)===null||n===void 0?void 0:n.call(o)(a.id,a.itemGroupId);break;default:const e=this.type;throw new Error(e)}}render(){return r(i,null,r("slot",null))}static get watchers(){return{manager:["onPropertyChange"],recommendationId:["onPropertyChange"],searchTerm:["onPropertyChange"],categoryTitle:["onPropertyChange"],category:["onPropertyChange"],filterCount:["onPropertyChange"],offset:["onPropertyChange"],limit:["onPropertyChange"],sort:["onPropertyChange"],options:["onPropertyChange"],type:["onPropertyChange"]}}};g=new WeakMap,C=new WeakMap,v=new WeakSet,b=async function e(){var t,r,i;const s=Object.assign({limit:this.limit,sort:this.sort,id:"klevuquery",offset:this.offset},this.options);switch(this.type){case"merchandising":{if(!this.category||!this.categoryTitle){throw new Error("Missing category or category title")}const e=await h(u(this.category,s,l(this.categoryTitle),m({filterManager:this.manager,limit:this.filterCount}),d(this.manager)));const r=e.queriesById("klevuquery");if(!r){console.error("KlevuQuery: Response meta",(t=e.apiResponse)===null||t===void 0?void 0:t.meta);throw new Error("KlevuQuery: Couldn't do fetch.")}y(this,C,r,"f");this.klevuQueryResult.emit({result:r,manager:this.manager});break}case"recommendation":{if(!this.recommendationId){throw new Error("Recommendation requires KMC id")}const e=await h(f(this.recommendationId));const t=e.queriesById("klevuquery");if(!t){console.error("KlevuQuery: Response meta",(r=e.apiResponse)===null||r===void 0?void 0:r.meta);throw new Error("KlevuQuery: Couldn't do fetch.")}y(this,C,t,"f");this.klevuQueryResult.emit({result:t,manager:this.manager});break}case"search":{if(!this.searchTerm){throw new Error("Search query requires search term")}const e=[];if(this.sendSearchViewEvent){e.push(p())}const t=await h(c(this.searchTerm,s,...e));const r=t.queriesById("klevuquery");if(!r){console.error("KlevuQuery: Response meta",(i=t.apiResponse)===null||i===void 0?void 0:i.meta);throw new Error("KlevuQuery: Couldn't do fetch.")}y(this,C,r,"f");this.klevuQueryResult.emit({result:r,manager:this.manager});break}default:const e=this.type;throw new Error(e)}};export{k as klevu_query};
//# sourceMappingURL=p-92b10312.entry.js.map