import{jsxs as e,Fragment as r,jsx as o}from"react/jsx-runtime";import t from"@heroicons/react/24/outline/ExclamationTriangleIcon";import i from"@heroicons/react/24/outline/LockClosedIcon";import{useState as n}from"react";import{u as s,f as l}from"./privy-context-Bi6vqCPc.mjs";import{M as a,c,B as m}from"./ModalHeader-DffkxvO4.mjs";import{styled as d}from"styled-components";import{S as p}from"./Subtitle-CV-2yKE4.mjs";import{T as u}from"./Title-BnzYV3Is.mjs";import{r as y}from"./context-BKnOUECq.mjs";import{u as f}from"./internal-context-dfitw7Ot.mjs";import{u as h}from"./modal-context-DBwfUxD-.mjs";import{G as v}from"./useActiveWallet-BEfvREjE.mjs";import"@privy-io/are-addresses-equal";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"@privy-io/js-sdk-core";import"tinycolor2";import"viem/utils";import"./wallet-connect-58EobR5U.mjs";import"./errors-Dd6zfYtp.mjs";import"ofetch";import"./getPublicClient-D4yNgeGy.mjs";import"viem";import"viem/chains";import"eventemitter3";import"./events-context-BJ75xIIf.mjs";import"./index-BtwxknTg.mjs";import"zustand";import"react-device-detect";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";const g=d.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%;
`,w={component:()=>{let{user:d}=s(),{client:w,walletProxy:j,refreshSessionAndUser:x,closePrivyModal:b}=f(),I=h(),{entropyId:T,entropyIdVerifier:k}=I.data?.recoverWallet??{},[C,M]=n(!1),[S,A]=n(null),[P,U]=n(null);function W(){if(!C){if(P)return I.data?.setWalletPassword?.onFailure(P),void b();if(!S)return I.data?.setWalletPassword?.onFailure(Error("User exited set recovery flow")),void b()}}I.onUserCloseViaDialogOrKeybindRef.current=W;let E=!(!C&&!S);/*#__PURE__*/return e(r,P?{children:[/*#__PURE__*/o(a,{onClose:W},"header"),/*#__PURE__*/o(g,{$color:"var(--privy-color-error)",style:{alignSelf:"center"},children:/*#__PURE__*/o(t,{height:38,width:38,stroke:"var(--privy-color-error)"})}),/*#__PURE__*/o(u,{style:{marginTop:"0.5rem"},children:"Something went wrong"}),/*#__PURE__*/o(v,{style:{minHeight:"2rem"}}),/*#__PURE__*/o(c,{onClick:()=>U(null),children:"Try again"}),/*#__PURE__*/o(m,{})]}:{children:[/*#__PURE__*/o(a,{onClose:W},"header"),/*#__PURE__*/o(i,{style:{width:"3rem",height:"3rem",alignSelf:"center"}}),/*#__PURE__*/o(u,{style:{marginTop:"0.5rem"},children:"Automatically secure your account"}),/*#__PURE__*/o(p,{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."}),/*#__PURE__*/o(v,{style:{minHeight:"2rem"}}),/*#__PURE__*/o(c,{loading:C,disabled:E,onClick:()=>async function(){M(!0);try{let e=await w.getAccessToken(),r=l(d,T);if(!e||!j||!r)return;if(!(await j.setRecovery({accessToken:e,entropyId:T,entropyIdVerifier:k,existingRecoveryMethod:r.recoveryMethod,recoveryMethod:"privy"})).entropyId)throw Error("Unable to set recovery on wallet");let o=await x();if(!o)throw Error("Unable to set recovery on wallet");let t=l(o,r.address);if(!t)throw Error("Unabled to set recovery on wallet");A(!!o),setTimeout((()=>{I.data?.setWalletPassword?.onSuccess(t),b()}),y)}catch(e){U(e)}finally{M(!1)}}(),children:S?"Success":"Confirm"}),/*#__PURE__*/o(m,{})]})}};export{w as SetAutomaticRecoveryScreen,w as default};
//# sourceMappingURL=SetAutomaticRecoveryScreen-CDGv27dh.mjs.map
