import{O as P,L as R}from"./CircularLoading-ohVkmYRk.js";import{d as x,r as D,l as y,m as d,q as m,B as b,p as T,g as o,V as l,D as a,aJ as s,G as u,ak as A,al as q,bw as V,H as h,$ as g,aj as C,ap as B,T as $,S as N,e as S,bx as U}from"./jwt-decode.esm-Dca5fHH5.js";import{b as I,T as z,h as F}from"./router-D5wfdag3.js";import{_ as G}from"./AbstraLogo.vue_vue_type_script_setup_true_lang-VbWqKJaf.js";import{i as K}from"./string-BYR4BIXr.js";import{A as M}from"./index-BKOa5q_P.js";import"./index-Cyx2lZTa.js";import"./Logo-DAfI0pPB.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]="9d189d8f-3315-4236-813a-b429792dfb7c",c._sentryDebugIdIdentifier="sentry-dbid-9d189d8f-3315-4236-813a-b429792dfb7c")}catch{}})();const O={class:"form"},j={class:"header"},H={class:"description"},J={class:"description"},Q={class:"footer"},W={key:2,class:"loading"},X=x({__name:"Passwordless",emits:["done"],setup(c,{emit:i}){const e=D({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function v(){const t=e.value.info.email,n=K(t);return e.value.invalid=!n,n}let _;const r=async({isResend:t}={})=>{if(v()){e.value.stage="loading";try{await I.authenticate(e.value.info.email,t),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=t=>{if(!t){e.value.info.email="";return}e.value.info.email=t.toLowerCase()},p=async()=>{if(e.value.info?.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"}}},k=async t=>{await fetch(`https://admin.abstra.app/_hooks/notify-email-not-received?email=${t}`,{method:"GET"})},E=()=>{e.value.info&&(r({isResend:!0}),k(e.value.info.email))},L=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(t,n)=>(d(),y("div",O,[m("div",j,[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(C),{key:0,class:"section"},{default:u(()=>[m("div",H,l(a(s).translate("i18n_auth_info_description")),1),o(a(A),{"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:n[0]||(n[0]=V(()=>r(),["enter"])),onChange:n[1]||(n[1]=w=>f(w.target.value))},null,8,["value","placeholder"])]),_:1},8,["validate-status","help"]),o(a(h),{type:"primary",onClick:n[2]||(n[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(C),{key:1,class:"section"},{default:u(()=>[m("div",J,l(a(s).translate("i18n_auth_token_label",null,e.value.info)),1),o(a(A),{"has-feedback":"","validate-status":e.value.invalid?"error":""},{default:u(()=>[o(P,{value:e.value.token,"onUpdate:value":n[3]||(n[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"])):T("",!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:L},{default:u(()=>[g(l(a(s).translate("i18n_auth_edit_email")),1)]),_:1}),o(a(h),{disabled:!!e.value.secsToAllowResend,onClick:E},{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(R)])):T("",!0)]))}}),Y=B(X,[["__scopeId","data-v-5e3f799d"]]),Z={key:0,class:"login"},ee={key:1,class:"loading"},ae=x({__name:"Login",setup(c){const i=$(),e=N();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=r.split("/").at(-1);await i.push({path:k,query:{...e.query,redirect:f,"prev-redirect":void 0}});return}i.push({name:"home"})}const _=S(()=>!I.getAuthor());return U(()=>{_.value||v()}),(r,f)=>_.value?(d(),y("div",Z,[o(Y,{onDone:v})])):(d(),y("div",ee,[o(R)]))}}),de=B(ae,[["__scopeId","data-v-21812a5b"]]);export{de as default};
//# sourceMappingURL=Login-CCkwUShi.js.map
