import{L as A}from"./CircularLoading.cd545ab6.js";import{d as C,e as B,o as _,X as h,a as v,b as o,ec as i,u as a,eW as t,c as w,w as d,bH as I,eV as L,cv as R,aF as m,bP as p,cu as T,R as q,$ as x,eq as D,ed as V,f as $,dF as F}from"./vue-router.85c27f05.js";import{_ as K}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.88a9f19a.js";import{T as M}from"./router.6a11826f.js";import{i as N}from"./string.76b61cc9.js";import{a as y,E as S}from"./gateway.aa5a907a.js";import{M as U}from"./member.b1f6d6f2.js";import"./tables.8aae1278.js";import"./Logo.c8f3b91c.js";import"./popupNotifcation.db970277.js";import"./record.b6b15302.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},s=new Error().stack;s&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[s]="f92f99ce-cc41-4da8-a5ab-46ba4b19f0f2",r._sentryDebugIdIdentifier="sentry-dbid-f92f99ce-cc41-4da8-a5ab-46ba4b19f0f2")}catch{}})();const O={class:"form"},j={class:"header"},z={class:"description"},H={class:"description"},W={class:"footer"},X={key:2,class:"loading"},G=C({__name:"Passwordless",emits:["done"],setup(r,{emit:s}){const e=B({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function c(){const l=e.value.info.email,n=N(l);return e.value.invalid=!n,n}let u;const f=async()=>{if(!!c()){e.value.stage="loading";try{await y.authenticate(e.value.info.email),e.value.stage="collect-token",e.value.secsToAllowResend=120,clearInterval(u),u=setInterval(()=>{e.value.secsToAllowResend-=1,e.value.secsToAllowResend<=0&&clearInterval(u)},1e3)}catch{e.value.invalid=!0,e.value.stage="collect-info"}}},b=l=>{if(!l){e.value.info.email="";return}e.value.info.email=l.toLowerCase()},k=async()=>{var l;if(!!((l=e.value.info)!=null&&l.email)){e.value.stage="loading";try{const n=await y.verify(e.value.info.email,e.value.token);if(!n)throw new Error("[Passwordless] Login did not return an user");M.trackSession(),s("done",n),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},E=()=>{e.value.info&&f()},P=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(l,n)=>(_(),h("div",O,[v("div",j,[o(K,{"hide-text":"",size:"large"}),v("h2",null,i(a(t).translate("i18n_auth_validate_your_email_login",null,{brandName:"Abstra"})),1)]),e.value.stage==="collect-info"?(_(),w(a(T),{key:0,class:"section"},{default:d(()=>[v("div",z,i(a(t).translate("i18n_auth_info_description")),1),o(a(R),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_info_invalid_email"):""},{default:d(()=>[o(a(I),{type:"email",value:e.value.info.email,placeholder:a(t).translate("i18n_auth_enter_your_work_email"),onBlur:c,onKeyup:L(f,["enter"]),onChange:n[0]||(n[0]=g=>b(g.target.value))},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),o(a(p),{type:"primary",onClick:f},{default:d(()=>[m(i(a(t).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(_(),w(a(T),{key:1,class:"section"},{default:d(()=>[v("div",H,i(a(t).translate("i18n_auth_token_label",null,e.value.info)),1),o(a(R),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_token_invalid"):""},{default:d(()=>[o(a(I),{value:e.value.token,"onUpdate:value":n[1]||(n[1]=g=>e.value.token=g),type:"number",placeholder:a(t).translate("i18n_auth_enter_your_token"),onKeyup:L(k,["enter"])},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),o(a(p),{type:"primary",onClick:k},{default:d(()=>[m(i(a(t).translate("i18n_auth_token_verify_email")),1)]),_:1}),o(a(p),{onClick:P},{default:d(()=>[m(i(a(t).translate("i18n_auth_edit_email")),1)]),_:1}),o(a(p),{disabled:!!e.value.secsToAllowResend,onClick:E},{default:d(()=>[m(i(a(t).translate("i18n_auth_token_resend_email"))+" ("+i(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),v("div",W,i(a(t).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(_(),h("div",X,[o(A)])):q("",!0)]))}});const J=x(G,[["__scopeId","data-v-b9707eaf"]]),Q=async()=>{const r=await U.onboarding(),s=y.getAuthor();if(r.shouldBeOnboarded&&s){const e=`${S.onboarding}/schedule`,c=new URLSearchParams({token:s.jwt}),u=e+"?"+c;window.location.replace(u)}},Y={key:0,class:"login"},Z={key:1,class:"loading"},ee=C({__name:"Login",setup(r){const s=D(),e=V();async function c(){await Q(),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 u=$(()=>!y.getAuthor());return F(()=>{u.value||c()}),(f,b)=>u.value?(_(),h("div",Y,[o(J,{onDone:c})])):(_(),h("div",Z,[o(A)]))}});const _e=x(ee,[["__scopeId","data-v-e4e9b925"]]);export{_e as default};
//# sourceMappingURL=Login.af1c3d94.js.map
