"use strict";var e=require("react/jsx-runtime"),r=require("@heroicons/react/24/outline/EnvelopeIcon"),i=require("./Layouts-D3TOcPhm.js"),t=require("lucide-react"),s=require("react"),a=require("./context-rs-ygOK2.js"),u=require("./index-BoiKFBqR.js"),o=require("./internal-context-CdsQ3LEl.js"),n=require("./modal-context-BgeioxwT.js"),l=require("./privy-context-UTJouJ1x.js"),d=require("./useActiveWallet-dTc6deka.js"),c=require("./wallet-connect-BuohfvHK.js"),q=require("./ModalHeader-Cpls13mi.js"),m=require("./EmailInputForm-Y-nHsEtF.js"),p=require("./ErrorMessage-BfTVyue9.js"),j=require("./ScreenLayout-DaFW0I3a.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("styled-components"),require("@privy-io/js-sdk-core"),require("tinycolor2"),require("./toViemAccount-CopJpCYv.js"),require("jose"),require("eventemitter3"),require("./index-Ub4KpwSY.js"),require("zustand"),require("viem"),require("viem/utils"),require("./errors-CBapWvRs.js"),require("ofetch"),require("react-device-detect"),require("@coinbase/wallet-sdk"),require("@walletconnect/ethereum-provider"),require("./pkce-CmuJlEgn.js"),require("./paths-DizMb-lU.js"),require("./PrivyPluginContext-DsLtVhZA.js"),require("js-cookie"),require("@privy-io/ethereum"),require("viem/accounts"),require("mipd"),require("@scure/base"),require("./usePrivy-Dt4_yE6Q.js"),require("./use-unlink-wallet-DAxmY7kq.js"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("@privy-io/popup"),require("./events-context-Di6--rDg.js"),require("@headlessui/react"),require("@privy-io/urls"),require("./getEmbeddedConnectedWallet-D6YL2FS9.js"),require("./getPublicClient-CFd_sHBk.js"),require("viem/chains"),require("./frame-BHa-PKpX.js"),require("@privy-io/routes"),require("./use-deposit-address-CVyd0fqP.js"),require("x402/client"),require("@privy-io/api-base"),require("@privy-io/are-addresses-equal"),require("./use-sign-with-user-signer-BhoaqeNG.js"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("./Screen-8NusMFtu.js"),require("./index-ByFhjjzH.js");var v=/*#__PURE__*/h(r);const y=/*#__PURE__*/s.forwardRef(((r,i)=>{let[m,j]=s.useState(""),[h,v]=s.useState(""),[y,w]=s.useState(!1),{authenticated:S,user:f}=l.usePrivyContext(),{initUpdateEmail:k}=o.usePrivyInternal(),{navigate:b,setModalData:E,currentScreen:C}=n.usePrivyModal(),{enabled:A,token:P}=u.useCaptcha(),M=a.useAppConfig(),I=c.validateEmail(m)&&(M.disablePlusEmails&&m.includes("+")?(h||v("Please enter a valid email address without a '+'."),!1):(h&&v(""),!0)),U=y||!I,L=()=>{U||(!A||P||S?(async e=>{if(!f?.email)throw Error("User is required to have an email address to update it.");w(!0);try{await k({oldAddress:f.email.address,newAddress:m,captchaToken:e}),b("AwaitingPasswordlessCodeScreen")}catch(e){E({errorModalData:{error:e,previousScreen:C||"LandingScreen"}}),b("ErrorScreen")}w(!1)})(P):(E({captchaModalData:{callback:e=>{if(!f?.email)throw Error("User is required to have an email address to update it.");return k({oldAddress:f.email.address,newAddress:m,captchaToken:e})},userIntentRequired:!1,onSuccessNavigateTo:"AwaitingPasswordlessCodeScreen",onErrorNavigateTo:"ErrorScreen"}}),b("CaptchaScreen")))};/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsxs(x,{children:[h&&/*#__PURE__*/e.jsx(p.ErrorMessage,{style:{marginTop:"0.25rem",textAlign:"left"},children:h}),/*#__PURE__*/e.jsxs(g,{$error:!!h,children:[/*#__PURE__*/e.jsx(d.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(t.Mail,{})}),/*#__PURE__*/e.jsx("input",{ref:i,id:"email-input",type:"email",placeholder:"your@email.com",onChange:e=>j(e.target.value),onKeyUp:e=>{"Enter"===e.key&&L()},value:m,autoComplete:"email"}),r.stacked?null:/*#__PURE__*/e.jsx(q.EmbeddedButton,{isSubmitting:y,onClick:L,disabled:U,children:"Submit"})]})]}),r.stacked?/*#__PURE__*/e.jsx(q.PrimaryButton,{loadingText:null,loading:y,disabled:U,onClick:L,style:{width:"100%"},children:"Submit"}):null]})}));let x=m.InputContainerForm,g=m.EmailUpdateForm;const w=({title:r="Update your email",subtitle:t="Add the email address you'd like to use going forward. We'll send you a confirmation code"})=>/*#__PURE__*/e.jsx(j.ScreenLayout,{title:r,subtitle:t,icon:v.default,watermark:!0,children:/*#__PURE__*/e.jsx(i.BottomPusherContainer,{children:/*#__PURE__*/e.jsx(y,{stacked:!0})})}),S={component:()=>/*#__PURE__*/e.jsx(w,{})};exports.UpdateEmailScreen=S,exports.UpdateEmailScreenView=w,exports.default=S;
//# sourceMappingURL=UpdateEmailScreen-DwrX_Ghq.js.map
