import{V as M,aa as q,_ as w,H as C,J as Q,aL as J}from"./vendor-ux-KtPBvlG0.js";import{j as t,b6 as f,bu as X,cl as Z,T as b,Q as T,bb as ee,ak as B,z as O,a6 as te,at as se}from"./vendor-mui-core-DnR6WYuU.js";import{r as n,j as ie}from"./vendor-react-CTtPmzVP.js";import{T as g}from"./vendor-utils-BqKQizRf.js";import{u as ne,m as h,o as $,c as j,H as oe,aV as re}from"./index-DGg3AL9l.js";import{l as ae}from"./vendor-arcblock-DRfhQ9Yl.js";import{K as ce}from"./landing-page-DQd97swG.js";import{f as _}from"./index-DBs9Ljax.js";import{g as D}from"./get-safe-url-CqIO9371.js";import"./vendor-hooks-DpqqC65c.js";import"./lottie-web-4koyQiv_.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.fromBase64(p).toString();return re(o)?o:null}catch{return null}};function je(){const p=n.useRef(null),{session:o,connectApi:K}=ne(),{t:s,locale:l}=M(),[y,P]=n.useState(o.user?.email||""),[r,V]=n.useState(""),[x,v]=n.useState(!1),[z,H]=n.useState(!1),[c,W]=n.useState(!1),[F,I]=n.useState(!1),[E,N]=n.useState(!1),{wallet:u}=q(),[a]=ie(),L=a.get("inviter")||localStorage.getItem("inviter"),d=a.get("updateKyc")==="1";n.useEffect(()=>{const i=a.get("subject"),e=ue(i);e&&P(e)},[]),n.useEffect(()=>{o.user?.emailVerified&&d&&(I(!0),setTimeout(()=>{if(u&&h()){w(()=>import("./index-m1ZQT0sU.js").then(i=>i.i),[],import.meta.url).then(i=>{i.call("arcClosePage")});return}window.location.href=D(a.get("redirect")||"/")},1e3))},[o.user,d,u,a]);const G=n.useCallback(async i=>{i.preventDefault(),v(!0);try{await $.post(`/kyc/email/send?locale=${l}`,{email:y}),W(!0),C.success(s("login.issueKyc.codeSentSuccess"))}catch(e){C.error(_(e)),document.getElementById("email-input")?.focus()}finally{v(!1)}},[y,l,s]),S=n.useCallback(async i=>{i&&i.preventDefault(),v(!0);try{await $.post(`/kyc/email/verify?locale=${l}`,{code:r}),I(!0),K.open({locale:l,action:"issue-kyc",extraParams:{code:r,updateKyc:a.get("updateKyc")||"0",inviter:L||""},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:()=>{N(!0),K.close(),d?(o.refresh({showProgress:!1,forceRefreshToken:!0}),setTimeout(()=>{if(u&&h()){w(()=>import("./index-m1ZQT0sU.js").then(e=>e.i),[],import.meta.url).then(e=>{e.call("arcClosePage")});return}window.location.href=D(a.get("redirect")||"/")},1e3)):u&&h()&&w(()=>import("./index-m1ZQT0sU.js").then(e=>e.i),[],import.meta.url).then(e=>{e.call("arcClosePage")})},onError:e=>{C.error(_(e))}})}catch(e){I(!1),C.error(_(e)),document.getElementById(`code-input-${g(r).length-1}`)?.focus()}finally{v(!1)}},[r,l,a,d,u,L]);n.useEffect(()=>{c&&g(r).length===j.VERIFY_CODE_LENGTH&&S()},[r,S,c]);const Y=n.useCallback(()=>{H(!0),K.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()){w(()=>import("./index-m1ZQT0sU.js").then(i=>i.i),[],import.meta.url).then(i=>{i.call("arcClosePage")});return}window.location.href=D(a.get("redirect")||"/")},2e3)},onError:i=>{C.error(_(i))}})},[l,a,u]),k=n.useCallback(i=>{if(!c)return;i.preventDefault();const e=g(i.clipboardData.getData("text/plain").slice(0,j.VERIFY_CODE_LENGTH));if(!/^\d+$/.test(e))return;V(e.padEnd(j.VERIFY_CODE_LENGTH," "));const m=document.getElementById(`code-input-${e.length}`);m&&m.focus()},[c]);n.useEffect(()=>(document.addEventListener("paste",k),()=>{document.removeEventListener("paste",k)}),[k]);const A=h()?s("login.issueKyc.issueTitle"):s("login.issueKyc.verifyTitle"),U=h()?s("login.issueKyc.issueAction"):s("login.issueKyc.verifyAction");return t.jsxs(ce,{did:window.blocklet?.appPid,children:[t.jsx(oe,{children:t.jsxs("title",{children:[A," | ",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:[E?t.jsx(X,{sx:{fontSize:72},color:"success"}):t.jsx(Z,{sx:{fontSize:72},color:"primary"}),t.jsx(b,{variant:"h5",sx:{textAlign:"center"},children:A}),!E&&t.jsx(b,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:s("login.issueKyc.pageDescription")}),E&&t.jsx(b,{variant:"body1",sx:{textAlign:"center"},children:s("login.issueKyc.success")}),E&&t.jsx(T,{variant:"contained",color:"primary",component:ee,href:"/",size:"large",children:s("login.issueKyc.backToHome")}),!E&&o.user&&t.jsxs(f,{direction:"column",sx:{justifyContent:"center",alignItems:"center"},children:[t.jsx(b,{variant:"body2",sx:{color:"info.main",textAlign:"center",mt:1},children:s("login.issueKyc.issueTarget",{action:U})}),t.jsxs(f,{direction:"row",spacing:1,sx:{justifyContent:"center",alignItems:"center",width:"100%",maxWidth:360},children:[t.jsx(Q,{did:o.user.did,responsive:!0,copyable:!0,showQrcode:!1}),t.jsx(J,{locale:l,session:o,showRole:!0,showManageBlocklet:!1})]})]})]}),t.jsx(B,{ref:p,sx:{width:"100%"},children:!F&&!z&&t.jsxs(le,{onSubmit:c?S:G,children:[!c&&t.jsx(O,{type:"email",id:"email-input",placeholder:s("login.issueKyc.emailPlaceholder"),sx:{width:"100%",maxWidth:360},value:y,onChange:i=>P(i.target.value),disabled:x,required:!0}),c&&t.jsxs(f,{direction:"column",spacing:2,sx:{justifyContent:"center",alignItems:"center"},children:[t.jsx(b,{variant:"body2",sx:{textAlign:"center"},children:s("login.issueKyc.codeSentMessage",{email:y})}),t.jsx(B,{sx:{width:"100%",maxWidth:360,display:"flex",justifyContent:"space-between"},children:[...Array(j.VERIFY_CODE_LENGTH)].map((i,e)=>t.jsx(O,{value:g(r[e])||"",type:"number",sx:{width:"14%"},onChange:m=>{const R=r.split("");R[e]=m.target.value,V(R.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:Y,size:"large",children:s("login.updateKyc.button")}),t.jsx(T,{type:"submit",size:"large",variant:"contained",disabled:x||!y||c&&g(r).length!==j.VERIFY_CODE_LENGTH,sx:{width:d?"auto":"100%"},children:x?t.jsx(te,{size:24}):s(c?"login.issueKyc.verifyButton":"login.issueKyc.sendCodeButton")})]})]})})]})]})}export{je as default};
