import{n as e,r as t,t as n}from"./password_changes-B_Q5-EtU.js";import{A as r,Ct as i,D as a,Dt as o,Et as s,M as c,N as l,O as u,Ot as d,P as f,W as p,ct as m,dt as h,jt as g,k as _,kt as v,mt as y,wt as b}from"./main-ChC-SNZa.js";import{t as x}from"./ButtonLink-CvJOjYPg.js";var S=g(),C=r(`
  mutation RecoverPassword($ticket: String!, $newPassword: String!) {
    setPasswordByRecovery(
      input: { ticket: $ticket, newPassword: $newPassword }
    ) {
      status
    }
  }
`),w=r(`
  mutation ResendRecoveryEmail($ticket: String!) {
    resendRecoveryEmail(input: { ticket: $ticket }) {
      status
      progressUrl
    }
  }
`),T=r(`
  fragment RecoverPassword_userRecoveryTicket on UserRecoveryTicket {
    username
    email
  }
`),E=r(`
  fragment RecoverPassword_siteConfig on SiteConfig {
    ...PasswordCreationDoubleInput_siteConfig
  }
`),D=r(`
  query PasswordRecovery($ticket: String!) {
    siteConfig {
      ...RecoverPassword_siteConfig
    }

    userRecoveryTicket(ticket: $ticket) {
      status
      ...RecoverPassword_userRecoveryTicket
    }
  }
`),O=e=>d({queryKey:[`passwordRecovery`,e],queryFn:({signal:t})=>_({query:D,signal:t,variables:{ticket:e}})}),k=()=>{let{t:e}=f();return(0,S.jsxs)(u,{children:[(0,S.jsx)(l,{Icon:h,title:e(`frontend.password_reset.consumed.title`),subtitle:e(`frontend.password_reset.consumed.subtitle`),invalid:!0}),(0,S.jsx)(x,{kind:`secondary`,to:`/`,reloadDocument:!0,children:e(`action.start_over`)})]})},A=e=>{let{t}=f(),n=c(T,e.userRecoveryTicket),r=o({mutationFn:async({ticket:e})=>{let t=await _({query:w,variables:{ticket:e}});if(t.resendRecoveryEmail.status===`SENT`){if(!t.resendRecoveryEmail.progressUrl)throw Error(`Unexpected response, missing progress URL`);window.location.href=t.resendRecoveryEmail.progressUrl,await new Promise(()=>void 0)}return t.resendRecoveryEmail}});return(0,S.jsxs)(u,{children:[(0,S.jsx)(l,{Icon:h,title:t(`frontend.password_reset.expired.title`),subtitle:t(`frontend.password_reset.expired.subtitle`,{email:n.email}),invalid:!0}),r.data?.status===`RATE_LIMITED`&&(0,S.jsx)(m,{type:`critical`,title:t(`frontend.errors.rate_limit_exceeded`)}),(0,S.jsxs)(y,{kind:`primary`,disabled:r.isPending,onClick:t=>{t.preventDefault(),r.mutate({ticket:e.ticket})},children:[!!r.isPending&&(0,S.jsx)(a,{inline:!0}),t(`frontend.password_reset.expired.resend_email`)]}),(0,S.jsx)(x,{kind:`secondary`,to:`/`,reloadDocument:!0,children:t(`action.start_over`)})]})},j=r=>{let{t:s}=f(),d=i(),h=c(E,r.siteConfig),g=c(T,r.userRecoveryTicket),v=o({mutationFn:async({ticket:e,form:t})=>{let n=t.get(`new_password`);if(n!==t.get(`new_password_again`))throw Error(`passwords mismatch; this should be checked by the form`);let r=await _({query:C,variables:{ticket:e,newPassword:n}});return r.setPasswordByRecovery.status===`ALLOWED`&&await d({to:`/`,reloadDocument:!0}),r.setPasswordByRecovery}}),y=async e=>{e.preventDefault();let t=new FormData(e.currentTarget);v.mutate({ticket:r.ticket,form:t})},b=v.error!==null,x=n(s,v.data?.status);return(0,S.jsx)(u,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,S.jsx)(l,{Icon:t,title:s(`frontend.password_reset.title`),subtitle:s(`frontend.password_reset.subtitle`)}),(0,S.jsxs)(p.Root,{onSubmit:y,method:`POST`,children:[b&&(0,S.jsx)(m,{type:`critical`,title:s(`frontend.password_change.failure.title`),children:s(`frontend.password_change.failure.description.unspecified`)}),x!==void 0&&(0,S.jsx)(m,{type:`critical`,title:s(`frontend.password_change.failure.title`),children:x}),(0,S.jsx)(`input`,{type:`hidden`,name:`username`,autoComplete:`username`,value:g.username}),(0,S.jsx)(e,{siteConfig:h,forceShowNewPasswordInvalid:v.data?.status===`INVALID_NEW_PASSWORD`||!1}),(0,S.jsxs)(p.Submit,{kind:`primary`,disabled:v.isPending,children:[!!v.isPending&&(0,S.jsx)(a,{inline:!0}),s(`action.save_and_continue`)]})]})]})})};function M(){let{ticket:e}=b({from:`/password/recovery/`}),{data:{siteConfig:t,userRecoveryTicket:n}}=v(O(e));if(!n)throw s();switch(n.status){case`EXPIRED`:return(0,S.jsx)(A,{ticket:e,userRecoveryTicket:n});case`CONSUMED`:return(0,S.jsx)(k,{});case`VALID`:return(0,S.jsx)(j,{ticket:e,siteConfig:t,userRecoveryTicket:n});default:{let e=n.status;throw Error(`Unhandled case: ${e}`)}}}export{M as component};
//# sourceMappingURL=password.recovery.index-B1S4qrYE.js.map