import{L}from"./CircularLoading-dfNnamlc.js";import{a as x,r as D,b as g,e as c,h as m,p as I,g as A,j as o,U as l,u as a,af as s,w as u,aK as R,aL as N,b6 as V,B as p,S as h,aJ as C,aN as B,ae as q,ac as U,c as $,V as S}from"./jwt-decode.esm-DyyavT6h.js";import{b as T,T as K,h as z}from"./router-BhKBgDIv.js";import{_ as F}from"./AbstraLogo.vue_vue_type_script_setup_true_lang-CirEJagM.js";import{O as M}from"./OTPInput-CPuVANSf.js";import{i as O}from"./string-C33uYcCb.js";import{A as j}from"./index-Bo37hDDz.js";import"./ts.worker-Do44s_XH.js";import"./Logo-BLceuW0a.js";(function(){try{var _=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},i=new Error().stack;i&&(_._sentryDebugIds=_._sentryDebugIds||{},_._sentryDebugIds[i]="3cb7f163-b622-486f-91bb-bc99d8e77c86",_._sentryDebugIdIdentifier="sentry-dbid-3cb7f163-b622-486f-91bb-bc99d8e77c86")}catch{}})();const G={class:"form"},J={class:"header"},H={class:"description"},Q={class:"description"},W={class:"footer"},X={key:2,class:"loading"},Y=x({__name:"Passwordless",emits:["done"],setup(_,{emit:i}){const v=i,e=D({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function f(){const t=e.value.info.email,n=O(t);return e.value.invalid=!n,n}let r;const d=async({isResend:t}={})=>{if(f()){e.value.stage="loading";try{await T.authenticate(e.value.info.email,t),e.value.stage="collect-token",e.value.secsToAllowResend=120,clearInterval(r),r=setInterval(()=>{e.value.secsToAllowResend-=1,e.value.secsToAllowResend<=0&&clearInterval(r)},1e3)}catch{e.value.invalid=!0,e.value.stage="collect-info"}}},y=t=>{if(!t){e.value.info.email="";return}e.value.info.email=t.toLowerCase()},k=async()=>{if(e.value.info?.email){e.value.stage="loading";try{const t=await T.verify(e.value.info.email,e.value.token);if(!t)throw new Error("[Passwordless] Login did not return an user");K.trackSession(),v("done",t),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},w=async t=>{await fetch(`https://admin.abstra.app/_hooks/notify-email-not-received?email=${t}`,{method:"GET"})},E=()=>{e.value.info&&(d({isResend:!0}),w(e.value.info.email))},P=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(t,n)=>(c(),g("div",G,[m("div",J,[o(F,{"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"?(c(),I(a(C),{key:0,class:"section"},{default:u(()=>[m("div",H,l(a(s).translate("i18n_auth_info_description")),1),o(a(R),{"has-feedback":"","validate-status":e.value.invalid?"error":"",help:e.value.invalid?a(s).translate("i18n_auth_info_invalid_email"):""},{default:u(()=>[o(a(N),{type:"email",value:e.value.info.email,placeholder:a(s).translate("i18n_auth_enter_your_work_email"),autofocus:"",onBlur:f,onKeyup:n[0]||(n[0]=V(()=>d(),["enter"])),onChange:n[1]||(n[1]=b=>y(b.target.value))},null,8,["value","placeholder"])]),_:1},8,["validate-status","help"]),o(a(p),{type:"primary",onClick:n[2]||(n[2]=()=>d())},{default:u(()=>[h(l(a(s).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(c(),I(a(C),{key:1,class:"section"},{default:u(()=>[m("div",Q,l(a(s).translate("i18n_auth_token_label",null,e.value.info)),1),o(a(R),{"has-feedback":"","validate-status":e.value.invalid?"error":""},{default:u(()=>[o(M,{value:e.value.token,"onUpdate:value":n[3]||(n[3]=b=>e.value.token=b),length:6,numeric:!0,size:"large",onCollectToken:k},null,8,["value"]),e.value.invalid?(c(),I(a(j),{key:0,message:a(s).translate("i18n_auth_token_invalid"),type:"error",style:{"margin-top":"24px"}},null,8,["message"])):A("",!0)]),_:1},8,["validate-status"]),o(a(p),{type:"primary",onClick:k},{default:u(()=>[h(l(a(s).translate("i18n_auth_token_verify_email")),1)]),_:1}),o(a(p),{onClick:P},{default:u(()=>[h(l(a(s).translate("i18n_auth_edit_email")),1)]),_:1}),o(a(p),{disabled:!!e.value.secsToAllowResend,onClick:E},{default:u(()=>[h(l(a(s).translate("i18n_auth_token_resend_email"))+" ("+l(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),m("div",W,l(a(s).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(c(),g("div",X,[o(L)])):A("",!0)]))}}),Z=B(Y,[["__scopeId","data-v-d18467d0"]]),ee={key:0,class:"login"},ae={key:1,class:"loading"},te=x({__name:"Login",setup(_){const i=q(),v=U();async function e(){const r=v.query.redirect,d=v.query["prev-redirect"],{status:y}=await z.getInfo();if(y!=="active"){i.push({name:"onboarding",query:{redirect:r,"prev-redirect":d}});return}if(r){const w=new URL(r,window.location.origin).pathname;await i.push({path:w,query:{...v.query,redirect:d,"prev-redirect":void 0}});return}i.push({name:"home"})}const f=$(()=>!T.getAuthor());return S(()=>{f.value||e()}),(r,d)=>f.value?(c(),g("div",ee,[o(Z,{onDone:e})])):(c(),g("div",ae,[o(L)]))}}),_e=B(te,[["__scopeId","data-v-2abe81c3"]]);export{_e as default};
//# sourceMappingURL=Login-B7gMpiAb.js.map
