import{L as C}from"./CircularLoading.c0497912.js";import{d as P,e as B,o as v,Y as h,a as f,b as n,e9 as r,u as a,c as b,w as d,S as D,eP as t,bL as I,eQ as A,cz as T,aG as m,bT as p,cy as L,a0 as R,eo as $,ea as q,f as K,dF as N}from"./index.b466b20d.js";import{_ as S}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.dd217b89.js";import{T as V,A as U}from"./router.3cd4b4c4.js";import{i as F}from"./string.42378387.js";import{a as y,E as z}from"./gateway.973a0055.js";import"./Logo.19805c7a.js";import"./Badge.4eadbb30.js";import"./popupNotifcation.d1201e83.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]="e5b329c4-2bc2-4a36-8ecf-8033d570b5ed",l._sentryDebugIdIdentifier="sentry-dbid-e5b329c4-2bc2-4a36-8ecf-8033d570b5ed")}catch{}})();const M={class:"form"},j={class:"header"},G={class:"description"},O={class:"description"},Q={class:"footer"},Y={key:2,class:"loading"},H=P({__name:"Passwordless",emits:["done"],setup(l,{emit:s}){const e=B({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function c(){const i=e.value.info.email,o=F(i);return e.value.invalid=!o,o}let _;const u=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(_),_=setInterval(()=>{e.value.secsToAllowResend-=1,e.value.secsToAllowResend<=0&&clearInterval(_)},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");V.trackSession(),s("done",o),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},x=()=>{e.value.info&&u()},E=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(i,o)=>(v(),h("div",M,[f("div",j,[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:d(()=>[f("div",G,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:d(()=>[n(a(I),{type:"email",value:e.value.info.email,placeholder:a(t).translate("i18n_auth_enter_your_work_email"),onBlur:c,onKeyup:A(u,["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:u},{default:d(()=>[m(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:d(()=>[f("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:d(()=>[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:d(()=>[m(r(a(t).translate("i18n_auth_token_verify_email")),1)]),_:1}),n(a(p),{onClick:E},{default:d(()=>[m(r(a(t).translate("i18n_auth_edit_email")),1)]),_:1}),n(a(p),{disabled:!!e.value.secsToAllowResend,onClick:x},{default:d(()=>[m(r(a(t).translate("i18n_auth_token_resend_email"))+" ("+r(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),f("div",Q,r(a(t).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(v(),h("div",Y,[n(C)])):D("",!0)]))}});const J=R(H,[["__scopeId","data-v-b9707eaf"]]),W=async l=>{const s=y.getAuthor();if(!s)return;const{status:e}=await U.getInfo();if(e==="active")return;const c=new URLSearchParams({token:s.jwt,status:e,...l&&{redirect:l}});window.location.replace(`${z.onboarding}/setup?${c}`)},X={key:0,class:"login"},Z={key:1,class:"loading"},ee=P({__name:"Login",setup(l){const s=$(),e=q();async function c(){const u=e.query.redirect;await W(u),u?await s.push({path:u,query:{...e.query,redirect:e.query["prev-redirect"],"prev-redirect":void 0}}):s.push({name:"home"})}const _=K(()=>!y.getAuthor());return N(()=>{_.value||c()}),(u,k)=>_.value?(v(),h("div",X,[n(J,{onDone:c})])):(v(),h("div",Z,[n(C)]))}});const de=R(ee,[["__scopeId","data-v-14389e9e"]]);export{de as default};
//# sourceMappingURL=Login.d1333275.js.map
