import{aS as A,b1 as O,r as t,b3 as T,b as P,cC as r,j as h,a$ as D}from"./index-ea7817a2.js";import{L as F,C as H}from"./ConsentForm-a04faf8f.js";const z=()=>{const f=A(),n=O(),[i,g]=t.useState(null),[R,C]=t.useState(),[l,c]=t.useState(!1),[E,u]=t.useState(!1),[d,m]=t.useState([]),L=new URLSearchParams(window.location.search),s=L.get("code"),o=L.get("state"),U=T(e=>e.loading.effects.auth.oauthLogin);t.useEffect(()=>{!i&&(!s||!o)&&f(P.auth.login),(async()=>{var S,w,x,b,N,j,k,v;const a=await n.auth.oauthLogin({data:{code:s,state:o}});if(a!=null&&a.error&&(a==null?void 0:a.message)==="Network Error"){r.delete();return}a!=null&&a.error?a.status===412&&a.data?(C(a.data),c(!0),m((S=a.data)!=null&&S.email&&((w=a.data)==null?void 0:w.email.length)>0?[(x=a.data)==null?void 0:x.email[0]]:[])):(g(a),c(!1),u(!1),r.delete()):(b=a.data)!=null&&b.email&&((N=a.data)==null?void 0:N.email.length)>1&&(C(a.data),u(!0),m((j=a.data)!=null&&j.email&&((k=a.data)==null?void 0:k.email.length)>0?[(v=a.data)==null?void 0:v.email[0]]:[]))})()},[s,o]);const y=t.useCallback(async()=>{const e=await n.auth.oauthLogin({data:{code:s,state:o,chosenEmail:d[0],consent:!0}});if(e!=null&&e.error&&(e==null?void 0:e.message)==="Network Error"){r.delete();return}e!=null&&e.error&&(g(e),c(!1),u(!1),r.delete())},[d,s,n.auth,o]);return U||!l&&!E&&i===null?h.jsx(D,{}):h.jsx(F,{error:i,register:!1,login:!0,loginHelp:!0,children:(l||E)&&h.jsx(H,{needConsent:l,remoteUser:R,chosenEmail:d,setChosenEmail:m,handleSubmit:y,onCancel:()=>f(P.auth.login)})})};export{z as default};
