var n=undefined&&undefined.__awaiter||function(n,o,i,e){function t(n){return n instanceof i?n:new i((function(o){o(n)}))}return new(i||(i=Promise))((function(i,c){function l(n){try{u(e.next(n))}catch(n){c(n)}}function r(n){try{u(e["throw"](n))}catch(n){c(n)}}function u(n){n.done?i(n.value):t(n.value).then(l,r)}u((e=e.apply(n,o||[])).next())}))};function o(o={productAttributes:["id","name","url","sku","imageUrl","price","salePrice"],productLimit:10,language:"en"}){return{klevuModifierId:"kleviyo",ssrOnResultFE:true,onResult:(i,e)=>{var t;if(!globalThis._learnq){globalThis._learnq=globalThis._learnq||[]}if(!["search","categoryMerchandising","recommendation","kmcRecommendation"].includes(e.klevuFunctionId)){console.error("Klevu Klaviyo modifier only works with search, categoryMerchandising, recommendation and kmcRecommendation functions");return}for(const c of(t=e.queries)!==null&&t!==void 0?t:[]){const e=`${c.id}-fallback`;const t=i.queryExists(e)?i.queriesById(`${c.id}-fallback`):i.queriesById(c.id);if(!t){continue}const l=t===null||t===void 0?void 0:t.records.slice(0,o.productLimit);if(!l||l.length==0){continue}let r;t.hooks.push((i=>n(this,void 0,void 0,(function*(){var n,e,c,u;if(!r){r=yield(n=t.annotationsById)===null||n===void 0?void 0:n.call(t,l[0].id,o.language)}const d=t.records.find((n=>n.id===i.productId));(e=globalThis._learnq)===null||e===void 0?void 0:e.push(["track",`Klevu ${i.type}`,{"Search Term":t.meta.searchedTerm,"Search Term(full)":(c=r===null||r===void 0?void 0:r.annotations)===null||c===void 0?void 0:c.fullTerm,Subjects:(u=r===null||r===void 0?void 0:r.annotations)===null||u===void 0?void 0:u.subjects,"Total Number of Product Results":t.meta.totalResultsFound,"Product Clicked":d&&o.productAttributes.reduce(((n,o)=>{n[o]=d[o];return n}),{}),"Search Results":l.map((n=>o.productAttributes.reduce(((o,i)=>{o[i]=n[i];return o}),{})))}])}))))}}}}export{o as k};
//# sourceMappingURL=p-49196da7.js.map