1import{bP as E,bN as C,aX as R,b_ as g,aP as I,cP as y,cO as P,aB as b,C as w,a as v,bX as A,cx as u,dG as T,dl as _,cf as d,aI as D,m as L,am as O,aF as F,aD as j,ao as N,as as k}from"./PopupSearchContainer-Bwfwi4m3.js";const H=(e,r)=>{const a=A(),o=E(),s=C(),n={[R]:g()};a&&(n[b]=a),o&&(n[w]=o),s&&(n[v]=s),I.createPurchaseEvent({orderId:e,items:r.map(({productId:c,quantity:S,price:t})=>({productId:c,quantity:S,price:t??null}))},{headers:n}).then(()=>{y(),P()}).catch(c=>{console.warn("RS: Purchase event failed",c)})},x="rs_purchase_events_sent",f=()=>{try{const e=sessionStorage.getItem(x);return e?new Set(JSON.parse(e)):new Set}catch{return new Set}},q=e=>{try{sessionStorage.setItem(x,JSON.stringify([...e]))}catch{}},G=()=>({sendPurchaseEvent:(e,r)=>{H(e,r)},getCartSessionId:E,resetCartSession:y,wasEventSent:e=>f().has(e),markEventSent:e=>{const r=f();r.add(e),q(r)},waitForDataLayer:(e,r=1e4)=>new Promise(a=>{const o=Date.now(),s=()=>{const n=window.dataLayer;if(Array.isArray(n)){const c=n.find(e);if(c){a(c);return}}Date.now()-o<r?setTimeout(s,100):a(null)};s()}),waitForSelector:(e,r=1e4)=>new Promise(a=>{const o=document.querySelector(e);if(o){a(o);return}let s=!1;const n=t=>{s||(s=!0,c.disconnect(),clearTimeout(S),a(t))},c=new MutationObserver(()=>{const t=document.querySelector(e);t&&n(t)});c.observe(document.body,{childList:!0,subtree:!0});const S=setTimeout(()=>{n(document.querySelector(e))},r)}),getFromDataLayer:e=>{const r=window.dataLayer;return Array.isArray(r)?r.find(e)??null:null}}),p=100,m=10,B=()=>({executed:!1,aborted:!1,generation:0,errorCount:0});function V(){const e=u.useRef(null),r=u.useRef(null),a=u.useRef(null),o=u.useRef(B()),s=u.useCallback(()=>{const t=o.current;if(t.aborted||t.executed||!e.current||!a.current)return;const i=t.generation;try{e.current(a.current).then(l=>{t.aborted||t.generation!==i||(l!==!1?t.executed=!0:r.current=setTimeout(s,p))}).catch(l=>{if(!(t.aborted||t.generation!==i)){if(t.errorCount++,console.error("RS: Purchase script error",l),t.errorCount>=m){console.warn("RS: Purchase script stopped after too many errors");return}r.current=setTimeout(s,p)}})}catch(l){if(t.errorCount++,console.error("RS: Purchase script execution error",l),t.errorCount>=m){console.warn("RS: Purchase script stopped after too many errors");return}r.current=setTimeout(s,p)}},[]),n=u.useCallback((t={})=>{const i=o.current;t.resetAborted&&(i.aborted=!1),t.incrementGeneration&&i.generation++,i.executed=!1,i.errorCount=0},[]),c=u.useCallback((t,i)=>{const l=typeof i=="string"?i.trim():"";if(n({resetAborted:!0,incrementGeneration:!0}),r.current&&(clearTimeout(r.current),r.current=null),!t||!l){e.current=null;return}try{e.current=new Function("helpers",`"use strict"; return (async () => { 2${l} 3})();`),a.current=G()}catch(h){console.error("RS: Failed to compile purchase script",h),e.current=null}},[n]),S=u.useCallback(()=>{n(),s()},[s,n]);return u.useEffect(()=>{const t=()=>{e.current&&(n({incrementGeneration:!0}),r.current&&clearTimeout(r.current),s())},i=history.pushState,l=history.replaceState;return history.pushState=function(...h){i.apply(this,h),t()},history.replaceState=function(...h){l.apply(this,h),t()},window.addEventListener("popstate",t),()=>{o.current.aborted=!0,history.pushState=i,history.replaceState=l,window.removeEventListener("popstate",t),r.current&&clearTimeout(r.current)}},[s,n]),{initFromSettings:c,startPolling:S}}const M=u.createContext({isInitialized:!1});function X({children:e}){const{purchaseScriptEnabled:r,purchaseScript:a}=T(),{body:o}=_("purchaseScript",a?.value),{initFromSettings:s,startPolling:n}=V(),c=u.useMemo(()=>({isInitialized:!!o.trim()}),[o]);return u.useEffect(()=>{const S=r?.value==="1";s(S,o),S&&o.trim()&&n()},[r,o,s,n]),d.jsx(M.Provider,{value:c,children:e})}function J(){return d.jsx(D,{children:d.jsx(L,{children:d.jsx(O,{children:d.jsx(X,{children:d.jsx(F,{children:d.jsx(j,{children:d.jsx(N,{children:d.jsx(k,{})})})})})})})})}export{J as S};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.