var p=Object.defineProperty;var g=(a,s,e)=>s in a?p(a,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[s]=e;var i=(a,s,e)=>(g(a,typeof s!="symbol"?s+"":s,e),e);import{M as l,W as o,A as n,c as u,w as m,C as E,a as A}from"./bundle-messageHandler.js";import{L as S}from"./bundle-login.js";class U extends l{constructor(){super(...arguments);i(this,"messageToHandle",o.messages.NUVEM_LOGGED_USER)}async handle(e){var r;try{const t=n.getCurrentUser();if(!t)return this.reply({cause:"NEW_CART",context:{storedCause:n.getLogoutCauseOnce()}},o.messages.NUVEM_CLEAR_AUTH_DATA);if(e.email&&e.email.toLocaleLowerCase()!==t.email.toLocaleLowerCase())return this.reply({cause:"EMAIL_MISMATCH",context:{payloadEmail:e.email,userEmail:t.email}},o.messages.NUVEM_NO_SESSION);const{user:d}=await this.api.getUser();return this.reply({user:u(d),storeId:n.getLoggedStore(),sessionExpirationDate:(r=n.getSessionExpirationDate())==null?void 0:r.toISOString()})}catch(t){return n.storeLogoutCause(t),this.replyError(t,o.messages.NUVEM_CLEAR_AUTH_DATA)}}}class _ extends l{constructor(){super(...arguments);i(this,"messageToHandle",o.messages.NUVEM_LOGOUT)}async handle(e){n.isAuthenticated()?(await this.api.logout(e),n.clearSession(),n.storeLogoutCause({cause:"User intentionally did logout"}),this.reply({success:!0})):this.reply({cause:"NO_SESSION"})}}class C extends l{constructor(){super(...arguments);i(this,"messageToHandle",o.messages.NUVEM_REQUEST);i(this,"methodsByResource",{createOrder:e=>this.api.createOrder(e),shouldShowOneTapSurvey:e=>this.api.shouldShowOneTapSurvey(e),sendCES:e=>this.api.sendCES(e),storeInfo:e=>this.api.getStoreInfo(e),deleteAddress:e=>this.api.deleteAddress(e.addressId),setAddressAsMain:e=>this.api.setAddressAsMain(e.addressId),createAbandonedCart:e=>this.api.createAbandonedCart(e),autocompleteCart:e=>this.api.autocompleteCart(e),exchangeToken:e=>this.api.exchangeToken(e),validateEmail:e=>this.api.validateEmail(e.otp),doesStorefrontUserEmailMatch:e=>this.api.doesStorefrontUserEmailMatch(e)})}async handle(e){const r=this.methodsByResource[e.resource];r||this.reply({error:"Request not allowed"}),this.reply(await r(e.body))}}var T=Object.defineProperty,M=Object.getOwnPropertyDescriptor,y=(a,s,e,r)=>{for(var t=M(s,e),d=a.length-1,h;d>=0;d--)(h=a[d])&&(t=h(s,e,t)||t);return t&&T(s,e,t),t};class c extends l{constructor(){super(...arguments);i(this,"messageToHandle",o.messages.NUVEM_PAYMENT_INIT)}handle(){return this.currentOrigin===E.CHECKOUT_SECURITY_HOST?this.reply({accessToken:n.getAccessToken()}):this.reply({error:"Invalid origin"}),Promise.resolve()}}y([m],c.prototype,"handle");class w extends l{constructor(){super(...arguments);i(this,"messageToHandle",o.messages.NUVEM_UPDATE_USER)}async handle(e){const r=await this.api.updateUser(e);this.reply(r)}}class H extends l{constructor(){super(...arguments);i(this,"messageToHandle",o.messages.NUVEM_ADD_ADDRESS)}async handle(e){const r=await this.api.updateAddressForUser(e);this.reply(r)}}class O extends A{constructor(){super(...arguments);i(this,"messageHandlers",[new U(this.api),new S(this.api),new _(this.api),new C(this.api),new c(this.api),new w(this.api),new H(this.api)]);i(this,"initialMessage",{message:o.messages.NUVEM_AUTH_DATA_READY,data:{isCrossStoreImpossible:!n.isCrossStorePossible()}})}}(function(){new O().init()})();