import{L as T}from"./CircularLoading.ce09a3f2.js";import{d as A,e as q,o as _,X as m,a as v,b as o,ec as s,u as a,eV as t,c as w,w as u,bH as b,eU as I,cv as L,aF as f,bP as p,cu as R,R as B,$ as x,eq as D,ed as E,f as $,dF as F}from"./vue-router.c5124aea.js";import{_ as K}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.1d6e5f8b.js";import{T as M}from"./router.09f8c7fd.js";import{a as h,E as N}from"./gateway.f0a8a4c2.js";import{M as U}from"./member.5f10a588.js";import"./tables.e3d4a0cb.js";import"./Logo.b4a8ebe2.js";import"./popupNotifcation.13f7057e.js";import"./record.3c40de6b.js";import"./string.243c4431.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},n=new Error().stack;n&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[n]="3e2e9fd1-4c8a-49c1-8784-0c419b87a8e6",l._sentryDebugIdIdentifier="sentry-dbid-3e2e9fd1-4c8a-49c1-8784-0c419b87a8e6")}catch{}})();const V={class:"form"},S={class:"header"},O={class:"description"},j={class:"description"},z={class:"footer"},H={key:2,class:"loading"},X=A({__name:"Passwordless",emits:["done"],setup(l,{emit:n}){const e=q({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});let i;const r=async()=>{e.value.stage="loading";try{await h.authenticate(e.value.info.email),e.value.stage="collect-token",e.value.secsToAllowResend=120,clearInterval(i),i=setInterval(()=>{e.value.secsToAllowResend-=1,e.value.secsToAllowResend<=0&&clearInterval(i)},1e3)}catch{e.value.invalid=!0,e.value.stage="collect-info"}},k=c=>{if(!c){e.value.info.email="";return}e.value.info.email=c.toLowerCase()},g=async()=>{var c;if(!!((c=e.value.info)!=null&&c.email)){e.value.stage="loading";try{const d=await h.verify(e.value.info.email,e.value.token);if(!d)throw new Error("[Passwordless] Login did not return an user");M.trackSession(),n("done",d),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},C=()=>{e.value.info&&r()},P=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(c,d)=>(_(),m("div",V,[v("div",S,[o(K,{"hide-text":"",size:"large"}),v("h2",null,s(a(t).translate("i18n_auth_validate_your_email_login",null,{brandName:"Abstra"})),1)]),e.value.stage==="collect-info"?(_(),w(a(R),{key:0,class:"section"},{default:u(()=>[v("div",O,s(a(t).translate("i18n_auth_info_description")),1),o(a(L),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_info_invalid_email"):""},{default:u(()=>[o(a(b),{value:e.value.info.email,placeholder:a(t).translate("i18n_auth_enter_your_work_email"),onKeyup:I(r,["enter"]),onChange:d[0]||(d[0]=y=>k(y.target.value))},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),o(a(p),{type:"primary",onClick:r},{default:u(()=>[f(s(a(t).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(_(),w(a(R),{key:1,class:"section"},{default:u(()=>[v("div",j,s(a(t).translate("i18n_auth_token_label",null,e.value.info)),1),o(a(L),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_token_invalid"):""},{default:u(()=>[o(a(b),{value:e.value.token,"onUpdate:value":d[1]||(d[1]=y=>e.value.token=y),type:"text",placeholder:a(t).translate("i18n_auth_enter_your_token"),onKeyup:I(g,["enter"])},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),o(a(p),{type:"primary",onClick:g},{default:u(()=>[f(s(a(t).translate("i18n_auth_token_verify_email")),1)]),_:1}),o(a(p),{onClick:P},{default:u(()=>[f(s(a(t).translate("i18n_auth_edit_email")),1)]),_:1}),o(a(p),{disabled:!!e.value.secsToAllowResend,onClick:C},{default:u(()=>[f(s(a(t).translate("i18n_auth_token_resend_email"))+" ("+s(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),v("div",z,s(a(t).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(_(),m("div",H,[o(T)])):B("",!0)]))}});const G=x(X,[["__scopeId","data-v-868a028a"]]),J=async()=>{const l=await U.onboarding(),n=h.getAuthor();if(l.shouldBeOnboarded&&n){const e=`${N.onboarding}/schedule`,i=new URLSearchParams({token:n.jwt}),r=e+"?"+i;window.location.replace(r)}},Q={key:0,class:"login"},W={key:1,class:"loading"},Y=A({__name:"Login",setup(l){const n=D(),e=E();async function i(){await J(),e.query.redirect?await n.push({path:e.query.redirect,query:{...e.query,redirect:e.query["prev-redirect"],"prev-redirect":void 0}}):n.push({name:"home"})}const r=$(()=>!h.getAuthor());return F(()=>{r.value||i()}),(k,g)=>r.value?(_(),m("div",Q,[o(G,{onDone:i})])):(_(),m("div",W,[o(T)]))}});const ue=x(Y,[["__scopeId","data-v-e4e9b925"]]);export{ue as default};
//# sourceMappingURL=Login.f58823df.js.map
