import{n as e}from"./chunk-Bh1tDfsg.js";import{i as t,l as n,s as r,t as i}from"./graphql-Dsv3IYEA.js";import{n as a,t as o}from"./LoadingSpinner-B8ofpgbZ.js";import{n as s,t as c}from"./jsx-runtime-BKZ-v_4m.js";import{n as l}from"./not-found-i5RsCZif.js";import{t as u}from"./useTranslation-l30fIyqu.js";import{n as d}from"./useNavigate-C0GZtrP6.js";import{t as f}from"./Button-BIiT28Ux.js";import{t as p}from"./Trans-C8BZbDlF.js";import{A as m,D as h,O as g,V as _,a as v,i as y}from"./main-CxGi0fIe.js";import{t as b}from"./ButtonLink-BcHfDxZ3.js";import{t as x}from"./arrow-left-zUhvGJXt.js";var S=e(s(),1),C=c();function w(e,t){return(0,C.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,viewBox:`0 0 24 24`,ref:t,...e,children:(0,C.jsx)(`path`,{d:`m21.211 12.895-16.14 8.07c-.785.392-1.658-.342-1.406-1.182L5.7 13h6.55a1 1 0 1 0 0-2H5.7L3.665 4.217c-.252-.84.621-1.574 1.405-1.182l16.141 8.07a1 1 0 0 1 0 1.79`})})}w.displayName=`SendSolidIcon`;var T=(0,S.forwardRef)(w),E=t(`
  mutation DoVerifyEmail($id: ID!, $code: String!) {
    completeEmailAuthentication(input: { id: $id, code: $code }) {
      status
    }
  }
`),D=t(`
  mutation ResendEmailAuthenticationCode($id: ID!, $language: String!) {
    resendEmailAuthenticationCode(input: { id: $id, language: $language }) {
      status
    }
  }
`);function O(){let{id:e}=y.useParams(),{data:{userEmailAuthentication:t}}=r(v(e));if(!t)throw l();let s=n(),c=d(),w=a({mutationFn:({id:e,code:t})=>i({query:E,variables:{id:e,code:t}}),async onSuccess(t){await s.invalidateQueries({queryKey:[`userEmails`]}),await s.invalidateQueries({queryKey:[`verifyEmail`,e]}),t.completeEmailAuthentication.status===`COMPLETED`?await c({to:`/`}):t.completeEmailAuthentication.status===`IN_USE`&&await c({to:`/emails/$id/in-use`,params:{id:e}})}}),O=a({mutationFn:({id:e,language:t})=>i({query:D,variables:{id:e,language:t}}),onSuccess(){k.current?.focus()}}),k=(0,S.useRef)(null),{t:A,i18n:j}=u(),M=e=>{e.preventDefault();let n=e.currentTarget,r=new FormData(n).get(`code`);w.mutateAsync({id:t.id,code:r}).finally(()=>n.reset())},N=()=>{O.mutate({id:t.id,language:j.languages[0]})},P=O.data?.resendEmailAuthenticationCode.status===`RESENT`,F=w.data?.completeEmailAuthentication.status===`INVALID_CODE`,I=w.data?.completeEmailAuthentication.status===`CODE_EXPIRED`,L=w.data?.completeEmailAuthentication.status===`RATE_LIMITED`;return(0,C.jsxs)(h,{children:[(0,C.jsx)(g,{Icon:T,title:A(`frontend.verify_email.heading`),subtitle:(0,C.jsx)(p,{i18nKey:`frontend.verify_email.enter_code_prompt`,values:{email:t.email},components:{email:(0,C.jsx)(`span`,{className:`text-primary`})}})}),(0,C.jsxs)(m.Root,{onSubmit:M,children:[P&&(0,C.jsx)(_,{type:`success`,title:A(`frontend.verify_email.email_sent_alert.title`),children:A(`frontend.verify_email.email_sent_alert.description`)}),F&&(0,C.jsx)(_,{type:`critical`,title:A(`frontend.verify_email.invalid_code_alert.title`),children:A(`frontend.verify_email.invalid_code_alert.description`)}),I&&(0,C.jsx)(_,{type:`critical`,title:A(`frontend.verify_email.code_expired_alert.title`),children:A(`frontend.verify_email.code_expired_alert.description`)}),L&&(0,C.jsx)(_,{type:`critical`,title:A(`frontend.errors.rate_limit_exceeded`)}),(0,C.jsxs)(m.Field,{name:`code`,serverInvalid:F||L,className:`self-center mb-4`,children:[(0,C.jsx)(m.Label,{children:A(`frontend.verify_email.code_field_label`)}),(0,C.jsx)(m.MFAControl,{ref:k}),F&&(0,C.jsx)(m.ErrorMessage,{children:A(`frontend.verify_email.code_field_error`)}),(0,C.jsx)(m.ErrorMessage,{match:`patternMismatch`,children:A(`frontend.verify_email.code_field_wrong_shape`)})]}),(0,C.jsxs)(m.Submit,{type:`submit`,disabled:w.isPending,children:[w.isPending&&(0,C.jsx)(o,{inline:!0}),A(`action.continue`)]}),(0,C.jsxs)(f,{type:`button`,kind:`secondary`,disabled:O.isPending,onClick:N,children:[O.isPending&&(0,C.jsx)(o,{inline:!0}),A(`frontend.verify_email.resend_code`)]}),(0,C.jsx)(b,{Icon:x,kind:`tertiary`,to:`/`,children:A(`action.back`)})]})]})}export{O as component};
//# sourceMappingURL=emails._id.verify-B-3elmAI.js.map