import{W as Y,af as Z,y as E,O as b,Z as G,aI as Q}from"./vendor-ux-bFYdDLNG.js";import{j as t,b3 as f,bg as J,ch as X,T as j,R as T,bb as ee,al as L,A as $,a7 as te,aT as se}from"./vendor-mui-core-CDEc-eG6.js";import{r as n,j as ie}from"./vendor-react-DX7tU9aY.js";import{ad as g}from"./vendor-utils-_C9URqjS.js";import{C as ne}from"./isEmail-BwGDo3Ws.js";import{u as oe,l as h,m as W,aY as v,H as re,aZ as ae}from"./index-DGZk149v.js";import{K as ce}from"./landing-page-C9IV5jp5.js";import{f as K}from"./index-DBs9Ljax.js";import{g as P}from"./get-safe-url-B1bR9jl-.js";import"./vendor-hooks-BrgYeCrj.js";import"./isIP-BBY240SU.js";import"./vendor-arcblock-DY2miJjh.js";import"./use-blocklet-logo-BSClbuwz.js";const le=se.form`
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  width: 100%;

  input[type='number']::-webkit-inner-spin-button,
  input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
  div.Mui-focused input {
    caret-color: ${p=>p.theme.palette.primary.main};
  }
`,ue=p=>{try{if(!p)return null;const o=ae(p).toString();return ne(o)?o:null}catch{return null}};function Ee(){const p=n.useRef(null),{session:o,connectApi:S}=oe(),{t:s,locale:l}=Y(),[y,A]=n.useState(o.user?.email||""),[r,B]=n.useState(""),[x,w]=n.useState(!1),[z,O]=n.useState(!1),[c,H]=n.useState(!1),[U,k]=n.useState(!1),[C,F]=n.useState(!1),{wallet:u}=Z(),[a]=ie(),D=a.get("inviter")||localStorage.getItem("inviter"),d=a.get("updateKyc")==="1";n.useEffect(()=>{const i=a.get("subject"),e=ue(i);e&&A(e)},[]),n.useEffect(()=>{o.user?.emailVerified&&d&&(k(!0),setTimeout(()=>{if(u&&h()){E(()=>import("./index-qpadg6GT.js").then(i=>i.i),[],import.meta.url).then(i=>{i.call("arcClosePage")});return}window.location.href=P(a.get("redirect")||"/")},1e3))},[o.user,d,u,a]);const N=n.useCallback(async i=>{i.preventDefault(),w(!0);try{await W.post(`/kyc/email/send?locale=${l}`,{email:y}),H(!0),b.success(s("login.issueKyc.codeSentSuccess"))}catch(e){b.error(K(e)),document.getElementById("email-input")?.focus()}finally{w(!1)}},[y,l,s]),I=n.useCallback(async i=>{i&&i.preventDefault(),w(!0);try{await W.post(`/kyc/email/verify?locale=${l}`,{code:r}),k(!0),S.open({locale:l,action:"issue-kyc",extraParams:{code:r,updateKyc:a.get("updateKyc")||"0",inviter:D||""},className:"connect",popup:!0,saveConnect:!1,forceConnected:!0,hideCloseButton:!0,messages:{title:s("login.issueKyc.claim"),scan:s("login.issueKyc.scan"),confirm:s("login.issueKyc.confirm"),success:s("login.issueKyc.success")},useSocket:!0,onSuccess:()=>{F(!0),S.close(),d?(o.refresh({showProgress:!1,forceRefreshToken:!0}),setTimeout(()=>{if(u&&h()){E(()=>import("./index-qpadg6GT.js").then(e=>e.i),[],import.meta.url).then(e=>{e.call("arcClosePage")});return}window.location.href=P(a.get("redirect")||"/")},1e3)):u&&h()&&E(()=>import("./index-qpadg6GT.js").then(e=>e.i),[],import.meta.url).then(e=>{e.call("arcClosePage")})},onError:e=>{b.error(K(e))}})}catch(e){k(!1),b.error(K(e)),document.getElementById(`code-input-${g(r).length-1}`)?.focus()}finally{w(!1)}},[r,l,a,d,u,D]);n.useEffect(()=>{c&&g(r).length===v&&I()},[r,I,c]);const M=n.useCallback(()=>{O(!0),S.open({locale:l,action:"update-kyc",className:"connect",popup:!0,saveConnect:!1,forceConnected:!0,hideCloseButton:!0,messages:{title:s("login.updateKyc.title"),scan:s("login.updateKyc.scan"),confirm:s("login.updateKyc.confirm"),success:s("login.updateKyc.success")},useSocket:!0,onSuccess:()=>{o.refresh({showProgress:!1,forceRefreshToken:!0}),setTimeout(()=>{if(u&&h()){E(()=>import("./index-qpadg6GT.js").then(i=>i.i),[],import.meta.url).then(i=>{i.call("arcClosePage")});return}window.location.href=P(a.get("redirect")||"/")},2e3)},onError:i=>{b.error(K(i))}})},[l,a,u]),_=n.useCallback(i=>{if(!c)return;i.preventDefault();const e=g(i.clipboardData.getData("text/plain").slice(0,v));if(!/^\d+$/.test(e))return;B(e.padEnd(v," "));const m=document.getElementById(`code-input-${e.length}`);m&&m.focus()},[c]);n.useEffect(()=>(document.addEventListener("paste",_),()=>{document.removeEventListener("paste",_)}),[_]);const R=h()?s("login.issueKyc.issueTitle"):s("login.issueKyc.verifyTitle"),q=h()?s("login.issueKyc.issueAction"):s("login.issueKyc.verifyAction");return t.jsxs(ce,{did:window.blocklet?.appPid,children:[t.jsx(re,{children:t.jsxs("title",{children:[R," | ",window.blocklet?.appName]})}),t.jsxs(f,{direction:"column",sx:{justifyContent:"center",alignItems:"center",width:"560px",px:2,boxSizing:"border-box",maxWidth:"100%",height:"100%"},children:[t.jsxs(f,{spacing:1,sx:{justifyContent:"center",alignItems:"center",mb:3},children:[C?t.jsx(J,{sx:{fontSize:72},color:"success"}):t.jsx(X,{sx:{fontSize:72},color:"primary"}),t.jsx(j,{variant:"h5",sx:{textAlign:"center"},children:R}),!C&&t.jsx(j,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:s("login.issueKyc.pageDescription")}),C&&t.jsx(j,{variant:"body1",sx:{textAlign:"center"},children:s("login.issueKyc.success")}),C&&t.jsx(T,{variant:"contained",color:"primary",component:ee,href:"/",size:"large",children:s("login.issueKyc.backToHome")}),!C&&o.user&&t.jsxs(f,{direction:"column",sx:{justifyContent:"center",alignItems:"center"},children:[t.jsx(j,{variant:"body2",sx:{color:"info.main",textAlign:"center",mt:1},children:s("login.issueKyc.issueTarget",{action:q})}),t.jsxs(f,{direction:"row",spacing:1,sx:{justifyContent:"center",alignItems:"center",width:"100%",maxWidth:360},children:[t.jsx(G,{did:o.user.did,responsive:!0,copyable:!0,showQrcode:!1}),t.jsx(Q,{locale:l,session:o,showRole:!0,showManageBlocklet:!1})]})]})]}),t.jsx(L,{ref:p,sx:{width:"100%"},children:!U&&!z&&t.jsxs(le,{onSubmit:c?I:N,children:[!c&&t.jsx($,{type:"email",id:"email-input",placeholder:s("login.issueKyc.emailPlaceholder"),sx:{width:"100%",maxWidth:360},value:y,onChange:i=>A(i.target.value),disabled:x,required:!0}),c&&t.jsxs(f,{direction:"column",spacing:2,sx:{justifyContent:"center",alignItems:"center"},children:[t.jsx(j,{variant:"body2",sx:{textAlign:"center"},children:s("login.issueKyc.codeSentMessage",{email:y})}),t.jsx(L,{sx:{width:"100%",maxWidth:360,display:"flex",justifyContent:"space-between"},children:[...Array(v)].map((i,e)=>t.jsx($,{value:g(r[e])||"",type:"number",sx:{width:"14%"},onChange:m=>{const V=r.split("");V[e]=m.target.value,B(V.join("")),m.target.value&&e<5&&document.getElementById(`code-input-${e+1}`)?.focus()},onKeyDown:m=>{m.key==="Backspace"&&!g(r[e])&&e>0&&document.getElementById(`code-input-${e-1}`)?.focus()},disabled:x,required:!0,id:`code-input-${e}`,autoComplete:"off",slotProps:{htmlInput:{maxLength:1,style:{textAlign:"center",fontSize:"1.5rem"},autoComplete:"off"}}},`code-input-${e}`))})]}),t.jsxs(f,{direction:"row",spacing:2,sx:{justifyContent:d?"space-between":"center",alignItems:"center",width:"100%",maxWidth:360},children:[d&&t.jsx(T,{variant:"text",disabled:x,onClick:M,size:"large",children:s("login.updateKyc.button")}),t.jsx(T,{type:"submit",size:"large",variant:"contained",disabled:x||!y||c&&g(r).length!==v,sx:{width:d?"auto":"100%"},children:x?t.jsx(te,{size:24}):s(c?"login.issueKyc.verifyButton":"login.issueKyc.sendCodeButton")})]})]})})]})]})}export{Ee as default};
