import{L as C}from"./CircularLoading.057be8a6.js";import{d as R,e as B,o as v,Y as g,a as f,b as n,e9 as r,u as a,c as b,w as _,S as q,eO as t,bL as I,eT as A,cz as T,aG as h,bT as y,cy as L,a0 as x,eo as D,ea as $,f as K,dF as N}from"./index.ea15e788.js";import{_ as S}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.e4aee598.js";import{T as U,A as V}from"./router.c735a703.js";import{i as F}from"./string.f9be58bd.js";import{a as k,E as z}from"./gateway.5334dd49.js";import"./Logo.57ffcb9b.js";import"./Badge.06a33f73.js";import"./popupNotifcation.b87da6c9.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]="f49f7e82-6630-4f87-9144-8216dc51ac41",l._sentryDebugIdIdentifier="sentry-dbid-f49f7e82-6630-4f87-9144-8216dc51ac41")}catch{}})();const M={class:"form"},O={class:"header"},j={class:"description"},G={class:"description"},Y={class:"footer"},H={key:2,class:"loading"},J=R({__name:"Passwordless",emits:["done"],setup(l,{emit:s}){const e=B({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function u(){const i=e.value.info.email,o=F(i);return e.value.invalid=!o,o}let d;const c=async()=>{if(!!u()){e.value.stage="loading";try{await k.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"}}},p=i=>{if(!i){e.value.info.email="";return}e.value.info.email=i.toLowerCase()},m=async()=>{var i;if(!!((i=e.value.info)!=null&&i.email)){e.value.stage="loading";try{const o=await k.verify(e.value.info.email,e.value.token);if(!o)throw new Error("[Passwordless] Login did not return an user");U.trackSession(),s("done",o),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},E=()=>{e.value.info&&c()},P=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(i,o)=>(v(),g("div",M,[f("div",O,[n(S,{"hide-text":"",size:"large"}),f("h2",null,r(a(t).translate("i18n_auth_validate_your_email_login",null,{brandName:"Abstra"})),1)]),e.value.stage==="collect-info"?(v(),b(a(L),{key:0,class:"section"},{default:_(()=>[f("div",j,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:_(()=>[n(a(I),{type:"email",value:e.value.info.email,placeholder:a(t).translate("i18n_auth_enter_your_work_email"),onBlur:u,onKeyup:A(c,["enter"]),onChange:o[0]||(o[0]=w=>p(w.target.value))},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),n(a(y),{type:"primary",onClick:c},{default:_(()=>[h(r(a(t).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(v(),b(a(L),{key:1,class:"section"},{default:_(()=>[f("div",G,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:_(()=>[n(a(I),{value:e.value.token,"onUpdate:value":o[1]||(o[1]=w=>e.value.token=w),type:"number",placeholder:a(t).translate("i18n_auth_enter_your_token"),onKeyup:A(m,["enter"])},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),n(a(y),{type:"primary",onClick:m},{default:_(()=>[h(r(a(t).translate("i18n_auth_token_verify_email")),1)]),_:1}),n(a(y),{onClick:P},{default:_(()=>[h(r(a(t).translate("i18n_auth_edit_email")),1)]),_:1}),n(a(y),{disabled:!!e.value.secsToAllowResend,onClick:E},{default:_(()=>[h(r(a(t).translate("i18n_auth_token_resend_email"))+" ("+r(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),f("div",Y,r(a(t).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(v(),g("div",H,[n(C)])):q("",!0)]))}});const Q=x(J,[["__scopeId","data-v-b9707eaf"]]),W=async(l,s)=>{const e=k.getAuthor();if(!e)return{onboarded:!1};const{status:u}=await V.getInfo();if(u==="active")return{onboarded:!0};const d=new URLSearchParams({token:e.jwt,status:u,...l&&{redirect:l},...s&&{"prev-redirect":s}});return window.location.replace(`${z.onboarding}/setup?${d}`),{onboarded:!1}},X={key:0,class:"login"},Z={key:1,class:"loading"},ee=R({__name:"Login",setup(l){const s=D(),e=$();async function u(){const c=e.query.redirect,p=e.query["prev-redirect"],{onboarded:m}=await W(c,p);!m||(c?await s.push({path:c,query:{...e.query,redirect:e.query["prev-redirect"],"prev-redirect":void 0}}):s.push({name:"home"}))}const d=K(()=>!k.getAuthor());return N(()=>{d.value||u()}),(c,p)=>d.value?(v(),g("div",X,[n(Q,{onDone:u})])):(v(),g("div",Z,[n(C)]))}});const de=x(ee,[["__scopeId","data-v-d0df64e7"]]);export{de as default};
//# sourceMappingURL=Login.fdfe06c0.js.map
