import{O as B,L as C}from"./CircularLoading.998b223a.js";import{d as L,r as D,o as d,a5 as y,e as m,f as o,ed as l,u as a,eH as s,a as b,b as u,bJ as q,eG as N,cx as T,g,bR as h,cw as R,h as x,_ as P,e5 as V,eb as $,c as U,dr as S}from"./jwt-decode.esm.54a1ea22.js";import{l as I,m as z,n as F}from"./router.4dfadf5d.js";import{_ as G}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.28bc9fc9.js";import{i as K}from"./string.61e11a30.js";import{A as M}from"./index.d53182ed.js";import"./index.c7a996a6.js";import"./Logo.65e0b37c.js";(function(){try{var c=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},i=new Error().stack;i&&(c._sentryDebugIds=c._sentryDebugIds||{},c._sentryDebugIds[i]="3ceca9e9-8656-4d9d-872b-15047e2b99a0",c._sentryDebugIdIdentifier="sentry-dbid-3ceca9e9-8656-4d9d-872b-15047e2b99a0")}catch{}})();const O={class:"form"},H={class:"header"},J={class:"description"},j={class:"description"},Q={class:"footer"},W={key:2,class:"loading"},X=L({__name:"Passwordless",emits:["done"],setup(c,{emit:i}){const e=D({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function v(){const n=e.value.info.email,t=K(n);return e.value.invalid=!t,t}let _;const r=async({isResend:n}={})=>{if(!!v()){e.value.stage="loading";try{await I.authenticate(e.value.info.email,n),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"}}},f=n=>{if(!n){e.value.info.email="";return}e.value.info.email=n.toLowerCase()},p=async()=>{var n;if(!!((n=e.value.info)!=null&&n.email)){e.value.stage="loading";try{const t=await I.verify(e.value.info.email,e.value.token);if(!t)throw new Error("[Passwordless] Login did not return an user");z.trackSession(),i("done",t),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},A=async n=>{await fetch(`https://admin.abstra.app/_hooks/notify-email-not-received?email=${n}`,{method:"GET"})},k=()=>{e.value.info&&(r({isResend:!0}),A(e.value.info.email))},E=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(n,t)=>(d(),y("div",O,[m("div",H,[o(G,{"hide-text":"",size:"large"}),m("h2",null,l(a(s).translate("i18n_auth_validate_your_email_login",null,{brandName:"Abstra"})),1)]),e.value.stage==="collect-info"?(d(),b(a(R),{key:0,class:"section"},{default:u(()=>[m("div",J,l(a(s).translate("i18n_auth_info_description")),1),o(a(T),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(s).translate("i18n_auth_info_invalid_email"):""},{default:u(()=>[o(a(q),{type:"email",value:e.value.info.email,placeholder:a(s).translate("i18n_auth_enter_your_work_email"),autofocus:"",onBlur:v,onKeyup:t[0]||(t[0]=N(()=>r(),["enter"])),onChange:t[1]||(t[1]=w=>f(w.target.value))},null,8,["value","placeholder"])]),_:1},8,["validate-status","help"]),o(a(h),{type:"primary",onClick:t[2]||(t[2]=()=>r())},{default:u(()=>[g(l(a(s).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(d(),b(a(R),{key:1,class:"section"},{default:u(()=>[m("div",j,l(a(s).translate("i18n_auth_token_label",null,e.value.info)),1),o(a(T),{"has-feedback":"","validate-status":e.value.invalid?"error":""},{default:u(()=>[o(B,{value:e.value.token,"onUpdate:value":t[3]||(t[3]=w=>e.value.token=w),length:6,numeric:!0,size:"large",onCollectToken:p},null,8,["value"]),e.value.invalid?(d(),b(a(M),{key:0,message:a(s).translate("i18n_auth_token_invalid"),type:"error",style:{"margin-top":"24px"}},null,8,["message"])):x("",!0)]),_:1},8,["validate-status"]),o(a(h),{type:"primary",onClick:p},{default:u(()=>[g(l(a(s).translate("i18n_auth_token_verify_email")),1)]),_:1}),o(a(h),{onClick:E},{default:u(()=>[g(l(a(s).translate("i18n_auth_edit_email")),1)]),_:1}),o(a(h),{disabled:!!e.value.secsToAllowResend,onClick:k},{default:u(()=>[g(l(a(s).translate("i18n_auth_token_resend_email"))+" ("+l(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),m("div",Q,l(a(s).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(d(),y("div",W,[o(C)])):x("",!0)]))}});const Y=P(X,[["__scopeId","data-v-d18467d0"]]),Z={key:0,class:"login"},ee={key:1,class:"loading"},ae=L({__name:"Login",setup(c){const i=V(),e=$();async function v(){const r=e.query.redirect,f=e.query["prev-redirect"],{status:p}=await F.getInfo();if(p!=="active"){i.push({name:"onboarding",query:{redirect:r,"prev-redirect":f}});return}if(r){const k=new URL(r,window.location.origin).pathname;await i.push({path:k,query:{...e.query,redirect:f,"prev-redirect":void 0}});return}i.push({name:"home"})}const _=U(()=>!I.getAuthor());return S(()=>{_.value||v()}),(r,f)=>_.value?(d(),y("div",Z,[o(Y,{onDone:v})])):(d(),y("div",ee,[o(C)]))}});const de=P(ae,[["__scopeId","data-v-2abe81c3"]]);export{de as default};
//# sourceMappingURL=Login.4e852955.js.map
