import{aa as S,p as T,q as I,s as b,j as e,m as w,l as i,u as p,a2 as C,b as l,d as h,L as y,P as f,R as D,M as m,i as x,I as E,B as A}from"./main-BiT4j4N5.js";import{t as N,I as q,P as L}from"./password_changes-g3oE0t0I.js";import{S as U}from"./Submit-fS0aoNPD.js";import{B as _}from"./ButtonLink-MFNyI4rM.js";import"./_commonjsHelpers-DaWZu8wl.js";/* empty css               */const M=i(`
  mutation RecoverPassword($ticket: String!, $newPassword: String!) {
    setPasswordByRecovery(
      input: { ticket: $ticket, newPassword: $newPassword }
    ) {
      status
    }
  }
`),O=i(`
  mutation ResendRecoveryEmail($ticket: String!) {
    resendRecoveryEmail(input: { ticket: $ticket }) {
      status
      progressUrl
    }
  }
`),k=i(`
  fragment RecoverPassword_userRecoveryTicket on UserRecoveryTicket {
    username
    email
  }
`),F=i(`
  fragment RecoverPassword_siteConfig on SiteConfig {
    ...PasswordCreationDoubleInput_siteConfig
  }
`),$=i(`
  query PasswordRecovery($ticket: String!) {
    siteConfig {
      ...RecoverPassword_siteConfig
    }

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