{"version":3,"file":"OfferGuard.DgCfHsBi.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/nSyZDAmrBxICeAT4JQ82/JvyH4JU07zdV8Rrqa0Hv/OfferGuard.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useRef,useState}from\"react\";import{useAuth}from\"https://framerusercontent.com/modules/HhRWwZczSNoa74ILHIk6/njrHUanXviwp34ybpdkF/authStore.js\";import{useCart}from\"https://framerusercontent.com/modules/XqNGxAwEfznulZmoChr3/3DmQl7cRPmbJhfHwljgw/cartStore.js\";import{useCurrentLocation}from\"https://framer.com/m/FramerDevGemsPublic-djHN.js\";import{RenderTarget}from\"framer\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";const isEditor=RenderTarget.current()===RenderTarget.canvas;const useOfferStore=createStore({errorMessage:\"\"});export function checkForOffer(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const{api,login}=useAuth();const{persistCart,setCartFromResponse}=useCart();const[offerStore,setOfferStore]=useOfferStore();const[,setCurrentLocation]=useCurrentLocation();const requestStarted=useRef(false);const[{guestToken,token}]=useState(()=>{if(typeof window===\"undefined\"){return{guestToken:null,token:null};}const params=new URLSearchParams(window.location.search);return{guestToken:params.get(\"guest_token\"),token:params.get(\"token\")};});useEffect(()=>{if(isEditor||requestStarted.current)return;requestStarted.current=true;// Existing guest offer flow\nif(guestToken){api.post(\"/cart/offer\",{guest_token:guestToken},{onSuccess:cart=>{persistCart(cart);setCurrentLocation(\"/bestil/tilbud\");},onValidationError:err=>{console.error(err);setOfferStore({errorMessage:err.message??\"Linket er ugyldigt\"});},onError:err=>{console.error(err);setOfferStore({errorMessage:\"Der skete en fejl, pr\\xf8v igen.\"});}});return;}// Authenticated offer flow from validateOffer\nif(token){api.post(\"/cart/user-offer\",{token,device_name:`Framer Web - ${navigator.platform}`},{onSuccess:data=>{login(data.token,data.user);persistCart(data.cart);setCartFromResponse(data.cart);setCurrentLocation(\"/bestil/tilbud\");},onValidationError:err=>{console.error(err);setOfferStore({errorMessage:err.message??\"Linket er ugyldigt\"});},onError:err=>{console.error(err);setOfferStore({errorMessage:\"Der skete en fejl, pr\\xf8v igen.\"});}});return;}// Neither token was supplied\nsetOfferStore({errorMessage:\"Linket er ugyldigt\"});},[guestToken,token]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props});});}export function withOfferError(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[offerStore,setOfferStore]=useOfferStore();return /*#__PURE__*/_jsx(Component,{ref:ref,...props,variant:!!offerStore.errorMessage?\"Error\":\"Default\",title:offerStore.errorMessage});});}\nexport const __FramerMetadata__ = {\"exports\":{\"checkForOffer\":{\"type\":\"reactHoc\",\"name\":\"checkForOffer\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withOfferError\":{\"type\":\"reactHoc\",\"name\":\"withOfferError\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"2SAA6mB,SAAgB,EAAc,EAAU,CAAC,OAAoB,GAAY,EAAM,IAAM,CAAC,GAAK,CAAC,MAAI,SAAO,EAAQ,EAAO,CAAC,cAAY,uBAAqB,EAAQ,EAAO,CAAC,EAAW,GAAe,EAAc,EAAO,EAAE,GAAoB,EAAmB,EAAQ,EAAeA,EAAO,EAAK,EAAO,CAAC,CAAC,aAAW,UAAQC,MAAa,CAAC,GAAU,IAAS,OAAa,MAAM,CAAC,WAAW,KAAK,MAAM,IAAI,EAAG,IAAM,EAAO,IAAI,gBAAgB,EAAO,SAAS,MAAM,EAAE,MAAM,CAAC,WAAW,EAAO,IAAI,aAAa,EAAE,MAAM,EAAO,IAAI,OAAO,CAAC,CAAE,CAAC,EAGtjC,OAHwjC,MAAc,CAAI,QAAU,EAAe,SAC5qC,IAD2rC,EAAe,QAAQ,GAC/sC,EAAW,CAAC,EAAI,KAAK,cAAc,CAAC,YAAY,CAAU,EAAE,CAAC,UAAU,GAAM,CAAC,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