"use strict";var e=require("react/jsx-runtime"),r=require("lucide-react"),i=require("react"),a=require("styled-components"),t=require("./context-rs-ygOK2.js"),n=require("./index-BoiKFBqR.js"),l=require("./internal-context-CdsQ3LEl.js"),s=require("./modal-context-BgeioxwT.js"),o=require("./privy-context-UTJouJ1x.js"),c=require("./useActiveWallet-dTc6deka.js"),u=require("./wallet-connect-BuohfvHK.js"),d=require("./ModalHeader-Cpls13mi.js"),m=require("./Chip-C6r7fZiR.js"),p=require("./EmailInputForm-Y-nHsEtF.js"),g=require("./ErrorMessage-BfTVyue9.js");const h=/*#__PURE__*/i.forwardRef(((a,p)=>{let[h,v]=i.useState(a.defaultValue||""),[S,q]=i.useState(""),[C,E]=i.useState(!1),{authenticated:b}=o.usePrivyContext(),{initLoginWithEmail:k}=l.usePrivyInternal(),{navigate:w,setModalData:P,currentScreen:f,data:M}=s.usePrivyModal(),{enabled:T,token:F}=n.useCaptcha(),[I,A]=i.useState(!1),{accountType:L}=c.useRecentlyUsedLogin(),R=t.useAppConfig(),U=u.validateEmail(h)&&(R.disablePlusEmails&&h.includes("+")?(S||q("Please enter a valid email address without a '+'."),!1):(S&&q(""),!0)),D=C||!U,N=()=>{var e;D||(P({login:M?.login,inlineError:void 0}),!T||F||b?(e=F,E(!0),k({email:h,captchaToken:e,disableSignup:M?.login?.disableSignup,withPrivyUi:!0}).then((()=>{w("AwaitingPasswordlessCodeScreen")})).catch((e=>{P({errorModalData:{error:e,previousScreen:f||"LandingScreen"}}),w("ErrorScreen")})).finally((()=>{E(!1)}))):(P({captchaModalData:{callback:e=>k({email:h,captchaToken:e,withPrivyUi:!0}),userIntentRequired:!1,onSuccessNavigateTo:"AwaitingPasswordlessCodeScreen",onErrorNavigateTo:"ErrorScreen"}}),w("CaptchaScreen")))};/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsxs(j,{children:[S&&/*#__PURE__*/e.jsx(g.ErrorMessage,{style:{display:"block",marginTop:"0.25rem",textAlign:"left"},children:S}),/*#__PURE__*/e.jsxs(x,{stacked:a.stacked,$error:!!S,children:[/*#__PURE__*/e.jsx(y,{children:/*#__PURE__*/e.jsx(r.Mail,{})}),/*#__PURE__*/e.jsx("input",{ref:p,id:"email-input",className:"login-method-button",type:"email",placeholder:"your@email.com",onFocus:()=>A(!0),onChange:e=>v(e.target.value),onKeyUp:e=>{"Enter"===e.key&&N()},value:h,autoComplete:"email"}),"email"!==L||I?a.stacked?/*#__PURE__*/e.jsx("span",{}):/*#__PURE__*/e.jsx(d.EmbeddedButton,{isSubmitting:C,onClick:N,disabled:D,children:"Submit"}):/*#__PURE__*/e.jsx(m.Chip,{color:"gray",children:"Recent"})]})]}),a.stacked?/*#__PURE__*/e.jsx(d.PrimaryButton,{loadingText:null,loading:C,disabled:D,onClick:N,style:{width:"100%"},children:"Submit"}):null]})}));let j=p.InputContainerForm,x=p.EmailInputForm,y=a.styled(c.LoginMethodIconWrapper)`
  display: inline-flex;
`;exports.ConnectEmailForm=h;
//# sourceMappingURL=ConnectEmailForm-C87PXIXT.js.map
