import{n as e}from"./chunk-DrgAwqJ9.js";import{i as t,l as n,s as r,t as i}from"./graphql-BME5mLgf.js";import{n as a,t as o}from"./LoadingSpinner-BR8GsFxa.js";import{n as s,t as c}from"./jsx-runtime-C3uB2UIS.js";import"./useStore-BnK_t0Uy.js";import{n as l}from"./not-found-D2Q6nITs.js";import"./link-DiTuM_g9.js";import{d as u,t as d}from"./useTranslation-DVVidJl_.js";import{n as f}from"./useNavigate-Dy0KAd9G.js";import{a as p,l as m,o as h,s as g,t as _}from"./Message-C3OrPzh0.js";import{t as v}from"./Button-BZSwK8Kg.js";import{t as y}from"./Submit-CmO9RMCD.js";import{t as b}from"./Trans-BxGYtb_x.js";import{n as x,t as S}from"./emails._id.verify-LOgEfaH_.js";import{C,S as w,T}from"./main-BpPO1zAy.js";import{t as E}from"./ButtonLink-BlaAAQga.js";import{t as D}from"./arrow-left-BiR6P5Cm.js";var O={container:`_container_43om7_10`,control:`_control_43om7_25`,digit:`_digit_43om7_49`},k=c(),A=e(s(),1),j=e(u(),1),M=({filled:e,selected:t})=>(0,k.jsx)(`div`,{className:O.digit,"aria-hidden":`true`,"data-filled":e?``:void 0,"data-selected":t?``:void 0}),N=(0,A.forwardRef)(function({className:e,length:t=6,...n},r){let i=(0,j.default)(O.container,e),[a,o]=A.useState(0),[s,c]=A.useState(null),l=e=>{let t=e.currentTarget;o(t.value?.length),document.activeElement!==t||t.selectionStart===null||t.selectionEnd===null?c(null):c([t.selectionStart,t.selectionEnd])};return(0,k.jsxs)(`div`,{className:i,children:[(0,k.jsx)(`input`,{...n,inputMode:`numeric`,type:`text`,minLength:0,maxLength:t,className:O.control,pattern:`\\d{${t}}`,autoComplete:`one-time-code`,onSelect:l,onFocus:l,onBlur:l,onMouseDown:l,onMouseMove:l,onMouseUp:l,onChange:l,ref:r}),Array.from(Array(t).keys()).map(e=>(0,k.jsx)(M,{filled:e<a,selected:!!s&&e>=s[0]&&e<s[1]},e))]})}),P=(0,A.forwardRef)(function(e,t){return(0,k.jsx)(m,{asChild:!0,children:(0,k.jsx)(N,{ref:t,...e})})});function F(e,t){return(0,k.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,k.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`})})}F.displayName=`SendSolidIcon`;var I=(0,A.forwardRef)(F),L=t(`
  mutation DoVerifyEmail($id: ID!, $code: String!) {
    completeEmailAuthentication(input: { id: $id, code: $code }) {
      status
    }
  }
`),R=t(`
  mutation ResendEmailAuthenticationCode($id: ID!, $language: String!) {
    resendEmailAuthenticationCode(input: { id: $id, language: $language }) {
      status
    }
  }
`);function z(){let{id:e}=S.useParams(),{data:{userEmailAuthentication:t}}=r(x(e));if(!t)throw l();let s=n(),c=f(),u=a({mutationFn:({id:e,code:t})=>i({query:L,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}})}}),m=a({mutationFn:({id:e,language:t})=>i({query:R,variables:{id:e,language:t}}),onSuccess(){O.current?.focus()}}),O=(0,A.useRef)(null),{t:j,i18n:M}=d(),N=e=>{e.preventDefault();let n=e.currentTarget,r=new FormData(n).get(`code`);u.mutateAsync({id:t.id,code:r}).finally(()=>n.reset())},F=()=>{m.mutate({id:t.id,language:M.languages[0]})},z=m.data?.resendEmailAuthenticationCode.status===`RESENT`,B=u.data?.completeEmailAuthentication.status===`INVALID_CODE`,V=u.data?.completeEmailAuthentication.status===`CODE_EXPIRED`,H=u.data?.completeEmailAuthentication.status===`RATE_LIMITED`;return(0,k.jsxs)(w,{children:[(0,k.jsx)(C,{Icon:I,title:j(`frontend.verify_email.heading`),subtitle:(0,k.jsx)(b,{i18nKey:`frontend.verify_email.enter_code_prompt`,values:{email:t.email},components:{email:(0,k.jsx)(`span`,{className:`text-primary`})}})}),(0,k.jsxs)(p,{onSubmit:N,children:[z&&(0,k.jsx)(T,{type:`success`,title:j(`frontend.verify_email.email_sent_alert.title`),children:j(`frontend.verify_email.email_sent_alert.description`)}),B&&(0,k.jsx)(T,{type:`critical`,title:j(`frontend.verify_email.invalid_code_alert.title`),children:j(`frontend.verify_email.invalid_code_alert.description`)}),V&&(0,k.jsx)(T,{type:`critical`,title:j(`frontend.verify_email.code_expired_alert.title`),children:j(`frontend.verify_email.code_expired_alert.description`)}),H&&(0,k.jsx)(T,{type:`critical`,title:j(`frontend.errors.rate_limit_exceeded`)}),(0,k.jsxs)(g,{name:`code`,serverInvalid:B||H,className:`self-center mb-4`,children:[(0,k.jsx)(h,{children:j(`frontend.verify_email.code_field_label`)}),(0,k.jsx)(P,{ref:O}),B&&(0,k.jsx)(_,{children:j(`frontend.verify_email.code_field_error`)}),(0,k.jsx)(_,{match:`patternMismatch`,children:j(`frontend.verify_email.code_field_wrong_shape`)})]}),(0,k.jsxs)(y,{type:`submit`,disabled:u.isPending,children:[u.isPending&&(0,k.jsx)(o,{inline:!0}),j(`action.continue`)]}),(0,k.jsxs)(v,{type:`button`,kind:`secondary`,disabled:m.isPending,onClick:F,children:[m.isPending&&(0,k.jsx)(o,{inline:!0}),j(`frontend.verify_email.resend_code`)]}),(0,k.jsx)(E,{Icon:D,kind:`tertiary`,to:`/`,children:j(`action.back`)})]})]})}export{z as component};
//# sourceMappingURL=emails._id.verify-YR1uBJy9.js.map