import{o as e}from"./rolldown-runtime.js";import{n as t,t as n}from"./jsx-runtime.js";import{Mt as r,Vt as i,_ as a,j as o,nt as s}from"./useActiveWallet-CEs8euQ3.js";import{k as c}from"./context-Cdw68BC2.js";import{t as l}from"./index-CKYEOQWW.js";import{t as u}from"./modal-context-DHfp-mFQ.js";import{t as d}from"./mail.js";import{i as f,l as p}from"./ModalHeader-BS54PZSj.js";import{t as m}from"./ScreenLayout-Dy-3vlz4.js";import{t as h}from"./EnvelopeIcon.js";import{t as g}from"./ErrorMessage-D8VaAP5m.js";import{n as _,r as v}from"./EmailInputForm-Dgoii4vf.js";import{i as y}from"./Layouts-BlFm53ED.js";var b=n(),x=e(t(),1);o();var S=(0,x.forwardRef)(((e,t)=>{let[n,o]=(0,x.useState)(``),[m,h]=(0,x.useState)(``),[_,v]=(0,x.useState)(!1),{authenticated:y,user:S}=r(),{initUpdateEmail:T}=i(),{navigate:E,setModalData:D,currentScreen:O}=u(),{enabled:k,token:A}=l(),j=c(),M=s(n)&&(j.disablePlusEmails&&n.includes(`+`)?(m||h(`Please enter a valid email address without a '+'.`),!1):(m&&h(``),!0)),N=_||!M,P=()=>{N||(!k||A||y?(async e=>{if(!S?.email)throw Error(`User is required to have an email address to update it.`);v(!0);try{await T({oldAddress:S.email.address,newAddress:n,captchaToken:e}),E(`AwaitingPasswordlessCodeScreen`)}catch(e){D({errorModalData:{error:e,previousScreen:O||`LandingScreen`}}),E(`ErrorScreen`)}v(!1)})(A):(D({captchaModalData:{callback:e=>{if(!S?.email)throw Error(`User is required to have an email address to update it.`);return T({oldAddress:S.email.address,newAddress:n,captchaToken:e})},userIntentRequired:!1,onSuccessNavigateTo:`AwaitingPasswordlessCodeScreen`,onErrorNavigateTo:`ErrorScreen`}}),E(`CaptchaScreen`)))};return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(C,{children:[m&&(0,b.jsx)(g,{style:{marginTop:`0.25rem`,textAlign:`left`},children:m}),(0,b.jsxs)(w,{$error:!!m,children:[(0,b.jsx)(a,{children:(0,b.jsx)(d,{})}),(0,b.jsx)(`input`,{ref:t,id:`email-input`,type:`email`,placeholder:`your@email.com`,onChange:e=>o(e.target.value),onKeyUp:e=>{e.key===`Enter`&&P()},value:n,autoComplete:`email`}),e.stacked?null:(0,b.jsx)(f,{isSubmitting:_,onClick:P,disabled:N,children:`Submit`})]})]}),e.stacked?(0,b.jsx)(p,{loadingText:null,loading:_,disabled:N,onClick:P,style:{width:`100%`},children:`Submit`}):null]})})),C=v,w=_,T=({title:e=`Update your email`,subtitle:t=`Add the email address you'd like to use going forward. We'll send you a confirmation code`})=>(0,b.jsx)(m,{title:e,subtitle:t,icon:h,watermark:!0,children:(0,b.jsx)(y,{children:(0,b.jsx)(S,{stacked:!0})})}),E={component:()=>(0,b.jsx)(T,{})};export{E as UpdateEmailScreen,E as default,T as UpdateEmailScreenView};