import{L as R}from"./CircularLoading.046b2d5c.js";import{d as C,e as B,o as c,X as h,a as v,b as n,e9 as r,u as a,c as b,w as u,R as $,eV as t,bH as I,eU as A,cv as T,aF as m,bP as p,cu as L,$ as P,eo as q,ea as D,f as V,dF as K}from"./vue-router.e3ef87f0.js";import{_ as N}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.d1e74e3b.js";import{T as F,b as S}from"./router.7553e78c.js";import{i as U}from"./string.5524ff61.js";import{a as y,E as M}from"./gateway.e3730daa.js";import"./Logo.19ebe967.js";import"./popupNotifcation.bf248d47.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},s=new Error().stack;s&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[s]="c43f4f3b-74d8-4df2-a9fb-74e6c637c475",l._sentryDebugIdIdentifier="sentry-dbid-c43f4f3b-74d8-4df2-a9fb-74e6c637c475")}catch{}})();const j={class:"form"},z={class:"header"},H={class:"description"},O={class:"description"},X={class:"footer"},G={key:2,class:"loading"},J=C({__name:"Passwordless",emits:["done"],setup(l,{emit:s}){const e=B({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function _(){const i=e.value.info.email,o=U(i);return e.value.invalid=!o,o}let d;const f=async()=>{if(!!_()){e.value.stage="loading";try{await y.authenticate(e.value.info.email),e.value.stage="collect-token",e.value.secsToAllowResend=120,clearInterval(d),d=setInterval(()=>{e.value.secsToAllowResend-=1,e.value.secsToAllowResend<=0&&clearInterval(d)},1e3)}catch{e.value.invalid=!0,e.value.stage="collect-info"}}},k=i=>{if(!i){e.value.info.email="";return}e.value.info.email=i.toLowerCase()},w=async()=>{var i;if(!!((i=e.value.info)!=null&&i.email)){e.value.stage="loading";try{const o=await y.verify(e.value.info.email,e.value.token);if(!o)throw new Error("[Passwordless] Login did not return an user");F.trackSession(),s("done",o),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},x=()=>{e.value.info&&f()},E=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(i,o)=>(c(),h("div",j,[v("div",z,[n(N,{"hide-text":"",size:"large"}),v("h2",null,r(a(t).translate("i18n_auth_validate_your_email_login",null,{brandName:"Abstra"})),1)]),e.value.stage==="collect-info"?(c(),b(a(L),{key:0,class:"section"},{default:u(()=>[v("div",H,r(a(t).translate("i18n_auth_info_description")),1),n(a(T),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_info_invalid_email"):""},{default:u(()=>[n(a(I),{type:"email",value:e.value.info.email,placeholder:a(t).translate("i18n_auth_enter_your_work_email"),onBlur:_,onKeyup:A(f,["enter"]),onChange:o[0]||(o[0]=g=>k(g.target.value))},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),n(a(p),{type:"primary",onClick:f},{default:u(()=>[m(r(a(t).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(c(),b(a(L),{key:1,class:"section"},{default:u(()=>[v("div",O,r(a(t).translate("i18n_auth_token_label",null,e.value.info)),1),n(a(T),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_token_invalid"):""},{default:u(()=>[n(a(I),{value:e.value.token,"onUpdate:value":o[1]||(o[1]=g=>e.value.token=g),type:"number",placeholder:a(t).translate("i18n_auth_enter_your_token"),onKeyup:A(w,["enter"])},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),n(a(p),{type:"primary",onClick:w},{default:u(()=>[m(r(a(t).translate("i18n_auth_token_verify_email")),1)]),_:1}),n(a(p),{onClick:E},{default:u(()=>[m(r(a(t).translate("i18n_auth_edit_email")),1)]),_:1}),n(a(p),{disabled:!!e.value.secsToAllowResend,onClick:x},{default:u(()=>[m(r(a(t).translate("i18n_auth_token_resend_email"))+" ("+r(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),v("div",X,r(a(t).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(c(),h("div",G,[n(R)])):$("",!0)]))}});const Q=P(J,[["__scopeId","data-v-b9707eaf"]]),W=async()=>{const l=y.getAuthor();if(!l)return;const{status:s}=await S.getInfo();if(s==="active")return;const e=new URLSearchParams({token:l.jwt,status:s});window.location.replace(`${M.onboarding}/setup?${e}`)},Y={key:0,class:"login"},Z={key:1,class:"loading"},ee=C({__name:"Login",setup(l){const s=q(),e=D();async function _(){await W(),e.query.redirect?await s.push({path:e.query.redirect,query:{...e.query,redirect:e.query["prev-redirect"],"prev-redirect":void 0}}):s.push({name:"home"})}const d=V(()=>!y.getAuthor());return K(()=>{d.value||_()}),(f,k)=>d.value?(c(),h("div",Y,[n(Q,{onDone:_})])):(c(),h("div",Z,[n(R)]))}});const ue=P(ee,[["__scopeId","data-v-e4e9b925"]]);export{ue as default};
//# sourceMappingURL=Login.3874e383.js.map
