import{a as Ee}from"/wp-web-assets/build/_shared/chunk-JM4MX6UF.js";import{a as G}from"/wp-web-assets/build/_shared/chunk-JP62YZFS.js";import{b as te}from"/wp-web-assets/build/_shared/chunk-ZMR2F4P6.js";import{a as B}from"/wp-web-assets/build/_shared/chunk-4KNITECB.js";import{a as ee}from"/wp-web-assets/build/_shared/chunk-HUIIU6KV.js";import{a as X}from"/wp-web-assets/build/_shared/chunk-LGVGYHK7.js";import{a as W}from"/wp-web-assets/build/_shared/chunk-PF5ZCBPA.js";import{b as Q}from"/wp-web-assets/build/_shared/chunk-6JBNEEY2.js";import{a as F}from"/wp-web-assets/build/_shared/chunk-7ZQSD6X7.js";import{j as z}from"/wp-web-assets/build/_shared/chunk-Z4SS4255.js";import{k as S}from"/wp-web-assets/build/_shared/chunk-A23LLNPE.js";import{a as D}from"/wp-web-assets/build/_shared/chunk-YA5N5DM6.js";import{C as j,u as P,x as L}from"/wp-web-assets/build/_shared/chunk-HSCJBJE6.js";import{a as Z,b as g}from"/wp-web-assets/build/_shared/chunk-Y2Y6GTTO.js";import{e as s}from"/wp-web-assets/build/_shared/chunk-6OSFCK5A.js";var he=s(Ee());var oe=(a,i,n,e)=>{if(e==null&&ge(i,a),n==null)ae(a,"1");else{let t=Number(n)+1;ae(a,t)}};var ge=(a,i)=>{var d;let n=new Date,e=(d=a==null?void 0:a.email_reverification_status)==null?void 0:d.days_between_reminders,m="; expires="+new Date(n.setDate(n.getDate()+e)).toString(),c="dbrc_"+i,l="1",y=c+"="+l+m+"; path=/; SameSite=Lax; Secure;";document.cookie=y},ae=(a,i)=>{let e="cnsc_"+a+"="+i+"; path=/; SameSite=Lax; Secure;";document.cookie=e};var ie={"home-sections-wrapper":"_0pDTY","home-swimlane-wrapper":"RNjGq","home-featured-carousel":"Hr-j4","home-swimlane-header":"BrVH-","home-sections-spacing":"Az6hT",modal:"Facwx",slide_in:"G1dCi",show:"DlK1b",toast:"c1WhL"};j();var _=s(Z());var C=s(D());var R={"contents-container":"_0vP9R","reminder-message":"lXt7Y","update-email-form":"_2s7Dz","button-container":"IN5j9","forgot-password":"TaNqW","submit-btn":"clxoc","password-error":"Vubdo","icon-container":"kgfc7"};var p=s(Z());j();var o=s(g()),J=()=>{console.error("Function not passed")},re=({handleUpdatedEmail:a=J,handleBack:i=J,handleCancel:n=J,currentEmail:e})=>{let{t}=S(),m=L(),c=(0,p.useContext)(X),l=t("You registered your account with %s. If this is incorrect, you can change your email here.",e),y=c==null?void 0:c.id,[d,w]=(0,p.useState)(""),[M,$]=(0,p.useState)(!1),[Y,I]=(0,p.useState)(!1),[k,U]=(0,p.useState)(""),[q,A]=(0,p.useState)(""),[O,V]=(0,p.useState)(!1),[x,ce]=(0,p.useState)();(0,p.useEffect)(()=>{m.data&&(m.data.changeEmailResponse.result==="SERVER_ERROR"?a(d,"ERROR"):m.data.changeEmailResponse.result==="FORM_ERROR"?ce(m.data.changeEmailResponse.message):m.data.changeEmailResponse.result==="SUCCESS"&&a(d,"NO_ERROR"))},[m.data]);let de=N=>{let u=N.target.value;pe(u),w(u)},ue=N=>{let u=N.target.value;fe(u)},pe=async N=>{let u=await te(N,t);U(u),$(u===null)},fe=async N=>{let u="";N?N!==d&&(u=t("Please ensure the email fields match.")):u=t("Please enter your email."),A(u),I(u==="")};return(0,o.jsx)(o.Fragment,{children:(0,o.jsxs)("div",{className:R["contents-container"],children:[(0,o.jsx)("h1",{children:t("Change email")}),(0,o.jsx)("div",{className:R["reminder-message"],dangerouslySetInnerHTML:{__html:l}}),(0,o.jsxs)(m.Form,{className:R["update-email-form"],method:"POST",children:[(0,o.jsx)("input",{type:"hidden",name:"id",value:y}),(0,o.jsx)("input",{type:"hidden",name:"_action",value:"email-confirm"}),(0,o.jsx)(W,{id:"newEmail",name:"newEmail",label:t("New Email"),customLabel:!0,className:`${B["form-control"]}`,validations:z,errorMessage:k,onBlur:de,isValid:M,fullWidth:!0}),(0,o.jsx)(W,{id:"confirmEmail",name:"confirmEmail",label:t("Confirm New Email"),customLabel:!0,className:`${B["form-control"]}`,validations:z,errorMessage:q,isValid:Y,onBlur:ue,fullWidth:!0}),(0,o.jsxs)("div",{className:G["password-container"],children:[(0,o.jsx)(W,{id:"password",label:t("Confirm Password"),customLabel:!0,className:`${B["form-control"]}`,type:O?"text":"password",name:"password",fullWidth:!0}),(0,o.jsx)("button",{type:"button",className:`${G["password-show"]} ${G["btn-no-background"]}`,"aria-label":t(O?"Hide password":"Show password"),onClick:()=>V(!O),children:t(O?"Hide":"Show")})]}),x&&(0,o.jsxs)("div",{className:R["password-error"],children:[(0,o.jsx)("div",{className:R["icon-container"],children:(0,o.jsx)(F,{name:"warning",height:"22",strokeColor:"var(--wp-neutral-25)",className:R["check-icon"]})}),x]}),(0,o.jsx)("a",{className:R["forgot-password"],href:"/forgot?nextUrl=settings",children:t("Forgot your password?")}),(0,o.jsxs)("div",{className:R["button-container"],children:[(0,o.jsx)("button",{className:R["submit-btn"],type:"submit",children:t("Change email")}),(0,o.jsx)(C.Button,{variant:C.ButtonVariant.SECONDARY,label:t("Cancel"),onClick:()=>n(),fullWidth:!0}),(0,o.jsx)(C.Button,{variant:C.ButtonVariant.TERTIARY,leadingIcon:C.IconNames.WpChevronLeft,label:t("Back"),onClick:()=>i(),fullWidth:!0})]})]})]})})};j();var ne=s(Z()),se=s(D());var f={"email-reverification-modal-content":"Zr5uv","email-reverification-heading":"QpmJZ","reverification-content":"ZxDMx","email-notes":"_1RDsx","email-text":"qKUEk","radio-wrapper":"Vyyd9","input-wrapper":"s-whY","btn-wrapper":"qqWTW"};var r=s(g()),Re=()=>{console.error("Function not passed")},le=({handleReverificationConfirm:a=Re})=>{let{t:i}=S(),{email:n}=P(),[e,t]=(0,ne.useState)(!0),m=l=>{let y=["gmail.com","gmail.com.br","gmail.de","gmail.dk","gmail.fr","googlemail.com"],d=l.split("@")[1];return y.includes(d)},c=l=>{t(l.target.value==="updateEmail")};return(0,r.jsxs)("div",{className:f["email-reverification-modal-content"],children:[(0,r.jsxs)("header",{className:f["email-reverification-heading"],children:[(0,r.jsx)("img",{src:"/wp-web-assets/images/wp-logo-orange.png",title:"Wattpad",width:"137",alt:""}),(0,r.jsx)("h1",{children:i("Please verify your email.")})]}),(0,r.jsxs)("div",{className:f["reverification-content"],children:[(0,r.jsx)("p",{className:f["email-notes"],children:i("In order to ensure continued access to your account, please check that the email below is correct and that you have access to it.")}),(0,r.jsx)("p",{className:f["email-notes"],children:i("Do you want to keep the email below as your recovery contact?")})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:f["email-text"],children:n}),m(n)&&(0,r.jsx)("p",{className:f["email-notes"],children:i("Note: If you are using a Gmail address with a period in it, the periods may not be displayed but emails will still reach you. ")})]}),(0,r.jsxs)("div",{className:f["radio-wrapper"],children:[(0,r.jsxs)("div",{className:f["input-wrapper"],children:[(0,r.jsx)("input",{name:"options",type:"radio",value:"updateEmail",checked:e,"aria-label":i("I need to update my email"),onChange:c}),(0,r.jsx)("label",{htmlFor:"option1",children:i("I need to update my email")})]}),(0,r.jsxs)("div",{className:f["input-wrapper"],children:[(0,r.jsx)("input",{name:"options",type:"radio",value:"noUpdateEmail",checked:!e,"aria-label":i("This is my current email"),onChange:c}),(0,r.jsx)("label",{htmlFor:"option2",children:i("This is my current email")})]}),(0,r.jsx)("div",{className:f["btn-wrapper"],children:(0,r.jsx)(se.Button,{label:i("Confirm"),onClick:()=>a(e),fullWidth:!0})})]})]})};var T=s(D());var E={"sent-email-modal-content":"_3Z2J0","modal-message":"_82p7l","checked-features":"ZArUE","check-and-feature":"xMEbX","check-icon":"U9--G","button-container":"B7jzo","change-email-btn":"pA-0P"};var v=s(g()),me=({newEmail:a,onChangeEmail:i,onResendEmail:n})=>{let{t:e}=S(),t=e("Please check your email %s to complete sign-up.",a)+" "+e("Please try again or change your email.");return(0,v.jsxs)("div",{className:E["sent-email-modal-content"],children:[(0,v.jsx)("h1",{children:e("Problem reaching email")}),(0,v.jsxs)("div",{className:E["modal-message"],children:[t.split(a)[0],(0,v.jsx)("strong",{children:a}),t.split(a)[1]]}),(0,v.jsxs)("div",{className:E["button-container"],children:[(0,v.jsx)("div",{className:E["change-email-btn"],children:(0,v.jsx)(T.Button,{label:e("Change email"),onClick:()=>i(),fullWidth:!0})}),(0,v.jsx)(T.Button,{variant:T.ButtonVariant.SECONDARY,label:e("Resend email"),onClick:()=>n(),fullWidth:!0})]})]})};var H=s(D());var h=s(g()),K=({newEmail:a,onDismiss:i,learnMoreState:n=!1})=>{let{t:e}=S(),t=e("Please check your email %s to complete sign-up.",a)+" "+e("After you click the link in your email, you'll be able to:"),m=[e("Vote on stories that you like"),e("Comment on stories and profiles"),e("Update your profile"),e("Create your stories, and more")];return(0,h.jsxs)("div",{className:E["sent-email-modal-content"],children:[(0,h.jsx)("h1",{children:e(n?"Please verify your email":"Email sent")}),(0,h.jsxs)("div",{className:E["modal-message"],children:[t.split(a)[0],(0,h.jsx)("strong",{children:a}),t.split(a)[1]]}),(0,h.jsx)("div",{className:E["checked-features"],children:m.map((c,l)=>(0,h.jsxs)("div",{className:E["check-and-feature"],children:[(0,h.jsx)(F,{name:"check",height:"22",strokeColor:"var(--wp-neutral-21)",className:E["check-icon"]}),(0,h.jsx)("div",{dangerouslySetInnerHTML:{__html:c}})]},l))}),!n&&(0,h.jsx)("div",{className:E["button-container"],children:(0,h.jsx)(H.Button,{variant:H.ButtonVariant.SECONDARY,label:e("Dismiss"),onClick:()=>i(),fullWidth:!0})})]})};var b=s(g());var tt=({onCloseModalCallback:a=()=>{},modalState:i="reverify",username:n,email:e})=>{let{verifyEmailData:t,currSkipsCookie:m,daysBetweenCookie:c}=P(),l=L(),y=ee(),[d,w]=(0,_.useState)(i),[M,$]=(0,_.useState)(e),[Y,I]=(0,_.useState)(!0);(0,_.useEffect)(()=>{I(!0)},[d]),(0,_.useEffect)(()=>{!l.data||l.state!=="idle"||(l.data.resendEmailError==="ERROR"?w("emailError"):l.data.resendEmailError==="NO_ERROR"&&w("sentEmail"))},[l.data]);let k=()=>{if(I(!1),y==="/home"){if(d==="sentEmail")return;oe(n,t,m,c)}a(!1)},U=(V,x)=>{$(V),x==="ERROR"?w("emailError"):x==="NO_ERROR"&&w("sentEmail")},q=V=>{V?w("changeEmail"):(I(!1),a(!0),l.load(`${y}?verifyEmail=${!0}`))},A=async()=>{l.load(`${y}?resendEmail=${!0}`)};return(0,b.jsx)(Q,{open:Y,closeModal:()=>{k()},customStyles:ie,showClose:!0,closePosition:"right",children:(()=>{switch(d){case"reverify":return(0,b.jsx)(le,{handleReverificationConfirm:q});case"changeEmail":return(0,b.jsx)(re,{currentEmail:e,handleCancel:k,handleBack:()=>w("reverify"),handleUpdatedEmail:U});case"sentEmail":return(0,b.jsx)(K,{newEmail:M,onDismiss:k});case"learnMore":return(0,b.jsx)(K,{newEmail:M,onDismiss:k,learnMoreState:!0});case"emailError":return(0,b.jsx)(me,{newEmail:M,onChangeEmail:()=>w("changeEmail"),onResendEmail:A});case"sendEmail":A()}})()})};export{ie as a,tt as b};