import{r as a,j as h}from"./vendor-react-wBh_31cN.js";import{u as y,d as R}from"./vendor-router-D1GqFWiT.js";import{j as T,u as U}from"./vendor-redux-CJZrIb6x.js";import{r as w,bg as s,aq as q}from"./index-BKr2rJhV.js";import{L as D}from"./login-card-xs6ESRfK.js";import{C as F}from"./ConsentForm-DXWIkGJ6.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./card-DISTA6Ay.js";import"./Hero-ILcN0sPk.js";import"./theme-colors-BFneJNsI.js";import"./LoginHelp-o3t9pY65.js";import"./getHopsDoc-BWSxyuXn.js";import"./input-H6_qmzms.js";import"./label-Dnebucx5.js";import"./combobox-CcK1PxyF.js";import"./input-group-Z3Qmt3PL.js";import"./textarea-Co48BFy3.js";import"./vendor-recharts-DmJlpLaF.js";const H=()=>{const g=y(),i=T(),[m,p]=a.useState(null),[A,C]=a.useState(),[l,n]=a.useState(!1),[E,u]=a.useState(!1),[d,c]=a.useState(),[f]=R(),{code:o,state:r}=a.useMemo(()=>({code:f.get("code"),state:f.get("state")}),[f]),O=U(e=>e.loading.effects.auth.oauthLogin);a.useEffect(()=>{!m&&(!o||!r)&&g(w.auth.login),(async()=>{var L,S,x,j,v,N,b,k;const t=await i.auth.oauthLogin({data:{code:o,state:r}});if(t!=null&&t.error&&(t==null?void 0:t.message)==="Network Error"){s.delete();return}t!=null&&t.error?t.status===412&&t.data?(C(t.data),n(!0),c((L=t.data)!=null&&L.email&&((S=t.data)==null?void 0:S.email.length)>0?(x=t.data)==null?void 0:x.email[0]:void 0)):(p(t),n(!1),u(!1),s.delete()):(j=t.data)!=null&&j.email&&((v=t.data)==null?void 0:v.email.length)>1&&(C(t.data),u(!0),c((N=t.data)!=null&&N.email&&((b=t.data)==null?void 0:b.email.length)>0?(k=t.data)==null?void 0:k.email[0]:void 0))})()},[o,r]);const P=a.useCallback(async()=>{const e=await i.auth.oauthLogin({data:{code:o,state:r,chosenEmail:d,consent:!0}});if(e!=null&&e.error&&(e==null?void 0:e.message)==="Network Error"){s.delete();return}e!=null&&e.error&&(p(e),n(!1),u(!1),s.delete())},[d,o,i.auth,r]);return O||!l&&!E&&m===null?h.jsx(q,{}):h.jsx(D,{error:m,register:!1,login:!0,loginHelp:!0,children:(l||E)&&h.jsx(F,{needConsent:l,remoteUser:A,chosenEmail:d,setChosenEmail:c,handleSubmit:P,onCancel:()=>g(w.auth.login)})})},it=a.memo(H);export{it as default};
