import{L as x}from"./CircularLoading.8e58ad1f.js";import{d as L,e as P,o as c,X as h,a as v,b as n,e9 as s,u as a,c as b,w as i,R as D,eV as t,bH as I,eU as T,cv as A,aF as m,bP as p,cu as C,$ as R,eo as V,ea as q,f as K,dF as N}from"./vue-router.f3adf768.js";import{_ as $}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.e25abc01.js";import{T as F}from"./router.e48ec16b.js";import{i as S}from"./string.10d66498.js";import{a as g}from"./gateway.9d2e1477.js";import"./Logo.68c86a36.js";import"./popupNotifcation.271a2b0b.js";(function(){try{var u=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},r=new Error().stack;r&&(u._sentryDebugIds=u._sentryDebugIds||{},u._sentryDebugIds[r]="c8ce4c6c-5756-4ad7-a382-421f70dd1125",u._sentryDebugIdIdentifier="sentry-dbid-c8ce4c6c-5756-4ad7-a382-421f70dd1125")}catch{}})();const M={class:"form"},U={class:"header"},z={class:"description"},H={class:"description"},X={class:"footer"},j={key:2,class:"loading"},G=L({__name:"Passwordless",emits:["done"],setup(u,{emit:r}){const e=P({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function _(){const l=e.value.info.email,o=S(l);return e.value.invalid=!o,o}let d;const f=async()=>{if(!!_()){e.value.stage="loading";try{await g.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=l=>{if(!l){e.value.info.email="";return}e.value.info.email=l.toLowerCase()},w=async()=>{var l;if(!!((l=e.value.info)!=null&&l.email)){e.value.stage="loading";try{const o=await g.verify(e.value.info.email,e.value.token);if(!o)throw new Error("[Passwordless] Login did not return an user");F.trackSession(),r("done",o),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},B=()=>{e.value.info&&f()},E=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(l,o)=>(c(),h("div",M,[v("div",U,[n($,{"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"?(c(),b(a(C),{key:0,class:"section"},{default:i(()=>[v("div",z,s(a(t).translate("i18n_auth_info_description")),1),n(a(A),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_info_invalid_email"):""},{default:i(()=>[n(a(I),{type:"email",value:e.value.info.email,placeholder:a(t).translate("i18n_auth_enter_your_work_email"),onBlur:_,onKeyup:T(f,["enter"]),onChange:o[0]||(o[0]=y=>k(y.target.value))},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),n(a(p),{type:"primary",onClick:f},{default:i(()=>[m(s(a(t).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(c(),b(a(C),{key:1,class:"section"},{default:i(()=>[v("div",H,s(a(t).translate("i18n_auth_token_label",null,e.value.info)),1),n(a(A),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(t).translate("i18n_auth_token_invalid"):""},{default:i(()=>[n(a(I),{value:e.value.token,"onUpdate:value":o[1]||(o[1]=y=>e.value.token=y),type:"number",placeholder:a(t).translate("i18n_auth_enter_your_token"),onKeyup:T(w,["enter"])},null,8,["value","placeholder","onKeyup"])]),_:1},8,["validate-status","help"]),n(a(p),{type:"primary",onClick:w},{default:i(()=>[m(s(a(t).translate("i18n_auth_token_verify_email")),1)]),_:1}),n(a(p),{onClick:E},{default:i(()=>[m(s(a(t).translate("i18n_auth_edit_email")),1)]),_:1}),n(a(p),{disabled:!!e.value.secsToAllowResend,onClick:B},{default:i(()=>[m(s(a(t).translate("i18n_auth_token_resend_email"))+" ("+s(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),v("div",X,s(a(t).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(c(),h("div",j,[n(x)])):D("",!0)]))}});const J=R(G,[["__scopeId","data-v-b9707eaf"]]),O={key:0,class:"login"},Q={key:1,class:"loading"},W=L({__name:"Login",setup(u){const r=V(),e=q();async function _(){e.query.redirect?await r.push({path:e.query.redirect,query:{...e.query,redirect:e.query["prev-redirect"],"prev-redirect":void 0}}):r.push({name:"home"})}const d=K(()=>!g.getAuthor());return N(()=>{d.value||_()}),(f,k)=>d.value?(c(),h("div",O,[n(J,{onDone:_})])):(c(),h("div",Q,[n(x)]))}});const se=R(W,[["__scopeId","data-v-39d82442"]]);export{se as default};
//# sourceMappingURL=Login.8082426f.js.map
