import{I as e,It as t,Q as n,T as r,bt as i,j as a,k as o,t as s,x as c}from"./_plugin-vue_export-helper-BVhEvvHC.js";import{D as l}from"./src-CD6Jsigc.js";import{t as u}from"./axios-DSyjHw-i.js";import{h as d,m as f}from"./useApi-CROJJdhE-bFLQvr8j.js";e(),i();var p={class:`email-auth`},m=s(a({__name:`EmailAuth`,props:{initialView:{}},setup(e){let i=e,a=d(),s=f(),m=c(()=>i.initialView??(s.path.endsWith(`/email`)?`login`:`choice`));function h(e){if(u.isAxiosError(e)){let t=e.response?.data;return typeof t==`string`&&t?t:void 0}}let g={async loginGoogle(e){if(e)try{await u.post(`/account/referral/pending`,{code:e})}catch{}return await u.post(`/account/login/restart`),await u.post(`/account/oauth2/login/google`),a.push({path:`/login/oauth2/wait`,query:{authType:`google`}}),{success:!0}},async loginEmail(e,t){try{return(await u.post(`/account/email/login`,{email:e,password:t})).data?.stage===`plans`?a.push(`/login/plans`):a.push({path:`/login/oauth2/wait`,query:{authType:`email`}}),{success:!0}}catch(e){if(u.isAxiosError(e)){let t=e.response?.status;return t===409?{success:!1,notConfirmed:!0}:t===401?{success:!1}:{success:!1,error:h(e)}}throw e}},async signUp(e,t,n){try{return await u.post(`/account/email/sign-up`,{email:e,password:t,referralCode:n??``}),{success:!0}}catch(e){if(u.isAxiosError(e)){let t=e.response?.status;if(t===409)return{success:!1,alreadyExists:!0};let n=h(e);return t===400&&n?.toLowerCase().includes(`referral`)?{success:!1,referralError:!0}:{success:!1,error:n}}throw e}},async confirmSignUp(e,t){try{return await u.post(`/account/email/confirm`,{email:e,code:t}),{success:!0}}catch(e){if(u.isAxiosError(e))return{success:!1,error:h(e)};throw e}},async resendCode(e){try{return await u.post(`/account/email/resend-code`,{email:e}),{success:!0}}catch(e){if(u.isAxiosError(e))return{success:!1,error:h(e)};throw e}},async forgotPassword(e){try{return await u.post(`/account/email/forgot-password`,{email:e}),{success:!0}}catch(e){if(u.isAxiosError(e))return{success:!1,error:h(e)};throw e}},async resetPassword(e,t,n){try{return await u.post(`/account/email/reset-password`,{email:e,code:t,newPassword:n}),{success:!0}}catch(e){if(u.isAxiosError(e))return{success:!1,error:h(e)};throw e}}};return(e,i)=>(n(),r(`div`,p,[o(t(l),{adapter:g,"product-name":t(`League Broadcast`),"initial-view":m.value},null,8,[`product-name`,`initial-view`])]))}}),[[`__scopeId`,`data-v-26a457d8`]]);export{m as default};