import{o as e}from"./rolldown-runtime.js";import{n as t,t as n}from"./jsx-runtime.js";import{Et as r,Mt as i,T as a,Vt as o,j as s,m as c}from"./useActiveWallet-CEs8euQ3.js";import{b as l}from"./context-Cdw68BC2.js";import{t as u}from"./modal-context-DHfp-mFQ.js";import{c as d,r as f,u as p}from"./ModalHeader-BS54PZSj.js";import{t as m}from"./ExclamationTriangleIcon.js";import{t as h}from"./LockClosedIcon.js";import{t as g}from"./Subtitle-CV-2yKE4.js";import{t as _}from"./Title-BnzYV3Is.js";var v=n(),y=e(t(),1);s();var b=a.div`
  && {
    border-width: 4px;
  }

  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  aspect-ratio: 1;
  border-style: solid;
  border-color: ${e=>e.$color??`var(--privy-color-accent)`};
  border-radius: 50%;
`,x={component:()=>{let{user:e}=i(),{client:t,walletProxy:n,refreshSessionAndUser:a,closePrivyModal:s}=o(),x=u(),{entropyId:S,entropyIdVerifier:C}=x.data?.recoverWallet??{},[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(null),[O,k]=(0,y.useState)(null);function A(){if(!w){if(O)return x.data?.setWalletPassword?.onFailure(O),void s();if(!E)return x.data?.setWalletPassword?.onFailure(Error(`User exited set recovery flow`)),void s()}}return x.onUserCloseViaDialogOrKeybindRef.current=A,(0,v.jsxs)(v.Fragment,O?{children:[(0,v.jsx)(f,{onClose:A},`header`),(0,v.jsx)(b,{$color:`var(--privy-color-error)`,style:{alignSelf:`center`},children:(0,v.jsx)(m,{height:38,width:38,stroke:`var(--privy-color-error)`})}),(0,v.jsx)(_,{style:{marginTop:`0.5rem`},children:`Something went wrong`}),(0,v.jsx)(c,{style:{minHeight:`2rem`}}),(0,v.jsx)(d,{onClick:()=>k(null),children:`Try again`}),(0,v.jsx)(p,{})]}:{children:[(0,v.jsx)(f,{onClose:A},`header`),(0,v.jsx)(h,{style:{width:`3rem`,height:`3rem`,alignSelf:`center`}}),(0,v.jsx)(_,{style:{marginTop:`0.5rem`},children:`Automatically secure your account`}),(0,v.jsx)(g,{style:{marginTop:`1rem`},children:`When you log into a new device, you’ll only need to authenticate to access your account. Never get logged out if you forget your password.`}),(0,v.jsx)(c,{style:{minHeight:`2rem`}}),(0,v.jsx)(d,{loading:w,disabled:!(!w&&!E),onClick:()=>async function(){T(!0);try{let i=await t.getAccessToken(),o=r(e,S);if(!i||!n||!o)return;if(!(await n.setRecovery({accessToken:i,entropyId:S,entropyIdVerifier:C,existingRecoveryMethod:o.recoveryMethod,recoveryMethod:`privy`})).entropyId)throw Error(`Unable to set recovery on wallet`);let c=await a();if(!c)throw Error(`Unable to set recovery on wallet`);let u=r(c,o.address);if(!u)throw Error(`Unabled to set recovery on wallet`);D(!!c),setTimeout((()=>{x.data?.setWalletPassword?.onSuccess(u),s()}),l)}catch(e){k(e)}finally{T(!1)}}(),children:E?`Success`:`Confirm`}),(0,v.jsx)(p,{})]})}};export{x as SetAutomaticRecoveryScreen,x as default};