import{O as D,L as x}from"./CircularLoading.19ad1ccf.js";import{d as L,r as q,o as c,ac as h,e as m,f as o,t as l,u as a,i as s,a as I,b as u,bQ as N,fn as V,cE as T,g as p,bY as g,cD as R,h as C,_ as E,c as $,dy as U,ec as S,eA as z}from"./jwt-decode.esm.7c9b757c.js";import{l as A,m as F,n as K}from"./router.95e6e4b6.js";import{_ as M}from"./AbstraLogo.vue_vue_type_script_setup_true_lang.7d3bd819.js";import{i as O}from"./string.fea0919a.js";import{A as G}from"./index.94f4853b.js";import"./index.33534fc9.js";import"./Logo.2bc39bab.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]="1d51d071-c9a8-4899-a475-5d09982b0392",_._sentryDebugIdIdentifier="sentry-dbid-1d51d071-c9a8-4899-a475-5d09982b0392")}catch{}})();const Q={class:"form"},Y={class:"header"},j={class:"description"},H={class:"description"},J={class:"footer"},W={key:2,class:"loading"},X=L({__name:"Passwordless",emits:["done"],setup(_,{emit:i}){const v=i,e=q({stage:"collect-info",info:{email:""},token:"",invalid:!1,secsToAllowResend:0});function f(){const n=e.value.info.email,t=O(n);return e.value.invalid=!t,t}let r;const d=async({isResend:n}={})=>{if(!!f()){e.value.stage="loading";try{await A.authenticate(e.value.info.email,n),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=n=>{if(!n){e.value.info.email="";return}e.value.info.email=n.toLowerCase()},k=async()=>{var n;if(!!((n=e.value.info)!=null&&n.email)){e.value.stage="loading";try{const t=await A.verify(e.value.info.email,e.value.token);if(!t)throw new Error("[Passwordless] Login did not return an user");F.trackSession(),v("done",t),e.value.stage="done"}catch{e.value.invalid=!0,e.value.stage="collect-token"}}},w=async n=>{await fetch(`https://admin.abstra.app/_hooks/notify-email-not-received?email=${n}`,{method:"GET"})},P=()=>{e.value.info&&(d({isResend:!0}),w(e.value.info.email))},B=()=>{e.value.stage="collect-info",e.value.info={email:""},e.value.token="",e.value.invalid=!1};return(n,t)=>(c(),h("div",Q,[m("div",Y,[o(M,{"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(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(N),{type:"email",value:e.value.info.email,placeholder:a(s).translate("i18n_auth_enter_your_work_email"),autofocus:"",onBlur:f,onKeyup:t[0]||(t[0]=V(()=>d(),["enter"])),onChange:t[1]||(t[1]=b=>y(b.target.value))},null,8,["value","placeholder"])]),_:1},8,["validate-status","help"]),o(a(g),{type:"primary",onClick:t[2]||(t[2]=()=>d())},{default:u(()=>[p(l(a(s).translate("i18n_auth_info_send_code")),1)]),_:1})]),_:1})):e.value.stage==="collect-token"?(c(),I(a(R),{key:1,class:"section"},{default:u(()=>[m("div",H,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(D,{value:e.value.token,"onUpdate:value":t[3]||(t[3]=b=>e.value.token=b),length:6,numeric:!0,size:"large",onCollectToken:k},null,8,["value"]),e.value.invalid?(c(),I(a(G),{key:0,message:a(s).translate("i18n_auth_token_invalid"),type:"error",style:{"margin-top":"24px"}},null,8,["message"])):C("",!0)]),_:1},8,["validate-status"]),o(a(g),{type:"primary",onClick:k},{default:u(()=>[p(l(a(s).translate("i18n_auth_token_verify_email")),1)]),_:1}),o(a(g),{onClick:B},{default:u(()=>[p(l(a(s).translate("i18n_auth_edit_email")),1)]),_:1}),o(a(g),{disabled:!!e.value.secsToAllowResend,onClick:P},{default:u(()=>[p(l(a(s).translate("i18n_auth_token_resend_email"))+" ("+l(e.value.secsToAllowResend)+" s) ",1)]),_:1},8,["disabled"]),m("div",J,l(a(s).translate("i18n_auth_token_footer_alternative_email")),1)]),_:1})):e.value.stage==="loading"?(c(),h("div",W,[o(x)])):C("",!0)]))}});const Z=E(X,[["__scopeId","data-v-d18467d0"]]),ee={key:0,class:"login"},ae={key:1,class:"loading"},te=L({__name:"Login",setup(_){const i=S(),v=z();async function e(){const r=v.query.redirect,d=v.query["prev-redirect"],{status:y}=await K.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=$(()=>!A.getAuthor());return U(()=>{f.value||e()}),(r,d)=>f.value?(c(),h("div",ee,[o(Z,{onDone:e})])):(c(),h("div",ae,[o(x)]))}});const ce=E(te,[["__scopeId","data-v-2abe81c3"]]);export{ce as default};
//# sourceMappingURL=Login.2f57a82d.js.map
