import{t as e}from"./chunk.window_CAbVMZox.esm.js";import{k as t,p as o,w as n}from"./chunk.register_Cnn1s0Rw.esm.js";import{t as a}from"./chunk.useDispatchEvent_D243iQEj.esm.js";const s=({defaultUxMode:e,uxMode:t})=>n((()=>{const n=o();return"windoid"===t&&n?e:t}),[e,t]);function i(t=e.location.origin,o,n,{credentials:a}={}){const s=`${t}/services/login_with_shop/finalize`;return(null==n?void 0:n.length)?fetch(s,{method:"POST",...a&&{credentials:a},headers:{"Content-Type":"application/json"},body:JSON.stringify({context_code:n})}).then((e=>{if(!e.ok)throw new Error(`Cookie exchange failed with status ${e.status}`);return e})).catch(o):fetch(s,{method:"GET",...a&&{credentials:a}}).catch(o)}const c=({handleClose:e,handleComplete:o,handleError:n,handleOpen:s,windoidRef:i})=>{const c=a();return t((async t=>{const a=i.current;switch(t.data.type){case"completed":{const e=await o(t.data);!1!==e&&(c("completed",e||t.data,!0),null==a||a.close());break}case"error":n&&!1===await n(t.data)||c("error",t.data),null==a||a.close();break;case"windoidopened":c("windoidopened"),await(null==s?void 0:s());break;case"close":case"windoidclosed":c("windoidclosed"),await(null==e?void 0:e()),null==a||a.close()}}),[c,o,e,n,s,i])};export{i as n,s as r,c as t}; //# sourceMappingURL=chunk.useWindoidMessageHandler_DeLL7FQR.esm.js.map