import{jsxs as e,Fragment as r,jsx as t}from"react/jsx-runtime";import o from"@heroicons/react/24/outline/EnvelopeIcon";import{B as i}from"./Layouts-BlFm53ED.mjs";import{Mail as m}from"lucide-react";import{forwardRef as s,useState as a}from"react";import{u as n}from"./context-BKnOUECq.mjs";import{a as l}from"./index-C5jxD-zy.mjs";import{u as p}from"./internal-context-dfitw7Ot.mjs";import{u as c}from"./modal-context-DBwfUxD-.mjs";import{u as d}from"./privy-context-Bi6vqCPc.mjs";import{m as u}from"./useActiveWallet-BEfvREjE.mjs";import{v as h}from"./wallet-connect-58EobR5U.mjs";import{E as j,P as v}from"./ModalHeader-DffkxvO4.mjs";import{I as f,E as y}from"./EmailInputForm-Dgoii4vf.mjs";import{E as g}from"./ErrorMessage-D8VaAP5m.mjs";import{S as k}from"./ScreenLayout-Caq5mGD8.mjs";import"styled-components";import"@privy-io/js-sdk-core";import"tinycolor2";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"eventemitter3";import"./index-BtwxknTg.mjs";import"zustand";import"viem";import"viem/utils";import"./errors-Dd6zfYtp.mjs";import"ofetch";import"react-device-detect";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"./paths-BH8W4zMc.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"js-cookie";import"@privy-io/ethereum";import"viem/accounts";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"@privy-io/popup";import"./events-context-BJ75xIIf.mjs";import"@headlessui/react";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"./getPublicClient-D4yNgeGy.mjs";import"viem/chains";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"@privy-io/are-addresses-equal";import"./use-sign-with-user-signer-CQI6hUH7.mjs";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"./Screen-D8KNyGVj.mjs";import"./index-Dq_xe9dz.mjs";const w=/*#__PURE__*/s(((o,i)=>{let[s,f]=a(""),[y,k]=a(""),[w,E]=a(!1),{authenticated:x,user:A}=d(),{initUpdateEmail:C}=p(),{navigate:P,setModalData:I,currentScreen:M}=c(),{enabled:T,token:q}=l(),L=n(),U=h(s)&&(L.disablePlusEmails&&s.includes("+")?(y||k("Please enter a valid email address without a '+'."),!1):(y&&k(""),!0)),D=w||!U,W=()=>{D||(!T||q||x?(async e=>{if(!A?.email)throw Error("User is required to have an email address to update it.");E(!0);try{await C({oldAddress:A.email.address,newAddress:s,captchaToken:e}),P("AwaitingPasswordlessCodeScreen")}catch(e){I({errorModalData:{error:e,previousScreen:M||"LandingScreen"}}),P("ErrorScreen")}E(!1)})(q):(I({captchaModalData:{callback:e=>{if(!A?.email)throw Error("User is required to have an email address to update it.");return C({oldAddress:A.email.address,newAddress:s,captchaToken:e})},userIntentRequired:!1,onSuccessNavigateTo:"AwaitingPasswordlessCodeScreen",onErrorNavigateTo:"ErrorScreen"}}),P("CaptchaScreen")))};/*#__PURE__*/return e(r,{children:[/*#__PURE__*/e(b,{children:[y&&/*#__PURE__*/t(g,{style:{marginTop:"0.25rem",textAlign:"left"},children:y}),/*#__PURE__*/e(S,{$error:!!y,children:[/*#__PURE__*/t(u,{children:/*#__PURE__*/t(m,{})}),/*#__PURE__*/t("input",{ref:i,id:"email-input",type:"email",placeholder:"your@email.com",onChange:e=>f(e.target.value),onKeyUp:e=>{"Enter"===e.key&&W()},value:s,autoComplete:"email"}),o.stacked?null:/*#__PURE__*/t(j,{isSubmitting:w,onClick:W,disabled:D,children:"Submit"})]})]}),o.stacked?/*#__PURE__*/t(v,{loadingText:null,loading:w,disabled:D,onClick:W,style:{width:"100%"},children:"Submit"}):null]})}));let b=f,S=y;const E=({title:e="Update your email",subtitle:r="Add the email address you'd like to use going forward. We'll send you a confirmation code"})=>/*#__PURE__*/t(k,{title:e,subtitle:r,icon:o,watermark:!0,children:/*#__PURE__*/t(i,{children:/*#__PURE__*/t(w,{stacked:!0})})}),x={component:()=>/*#__PURE__*/t(E,{})};export{x as UpdateEmailScreen,E as UpdateEmailScreenView,x as default};
//# sourceMappingURL=UpdateEmailScreen-RJlJqp4d.mjs.map
