import{u as P,p as _,ag as x,ah as S,s as j,r as I,d as R,m as b,j as s,L as y,P as v,R as A,N as c,F as D,g as E,K as L,M as u,i as N,l as O}from"./main-Bn3jZxQW.js";import{t as W,I as q,P as C}from"./password_changes-Dq_pjYei.js";import{S as M}from"./Submit-s3yrm_WK.js";import{B as $}from"./ButtonLink-DaMceLGU.js";import{S as k}from"./Separator-CmDle60m.js";import"./_commonjsHelpers-DaWZu8wl.js";/* empty css               */const F=O(`
  mutation ChangePassword(
    $userId: ID!
    $oldPassword: String!
    $newPassword: String!
  ) {
    setPassword(
      input: {
        userId: $userId
        currentPassword: $oldPassword
        newPassword: $newPassword
      }
    ) {
      status
    }
  }
`);function V(){const{t:r}=P(),{data:{viewer:n,siteConfig:l}}=_(x),w=S();if(n.__typename!=="User")throw j();const p=n.id,h=I.useRef(null),e=R({async mutationFn(a){const t=a.get("current_password"),i=a.get("new_password"),m=a.get("new_password_again");if(i!==m)throw new Error("passwords mismatch; this should be checked by the form");const d=await b({query:F,variables:{userId:p,oldPassword:t,newPassword:i}});return d.setPassword.status==="ALLOWED"&&w.navigate({to:"/password/change/success"}),d.setPassword}}),g=async a=>{a.preventDefault();const t=new FormData(a.currentTarget);e.mutate(t)},f=e.error!==null,o=W(r,e.data?.status);return s.jsx(y,{children:s.jsxs("div",{className:"flex flex-col gap-10",children:[s.jsx(v,{Icon:q,title:r("frontend.password_change.title"),subtitle:r("frontend.password_change.subtitle")}),s.jsxs(A,{onSubmit:g,method:"POST",children:[f&&s.jsx(c,{type:"critical",title:r("frontend.password_change.failure.title"),children:r("frontend.password_change.failure.description.unspecified")}),o!==void 0&&s.jsx(c,{type:"critical",title:r("frontend.password_change.failure.title"),children:o}),s.jsxs(D,{name:"current_password",serverInvalid:e.data?.status==="WRONG_PASSWORD",children:[s.jsx(E,{children:r("frontend.password_change.current_password_label")}),s.jsx(L,{required:!0,autoComplete:"current-password",ref:h}),s.jsx(u,{match:"valueMissing",children:r("frontend.errors.field_required")}),e.data&&e.data.status==="WRONG_PASSWORD"&&s.jsx(u,{children:r("frontend.password_change.failure.description.wrong_password")})]}),s.jsx(k,{}),s.jsx(C,{siteConfig:l,forceShowNewPasswordInvalid:e.data&&e.data.status==="INVALID_NEW_PASSWORD"||!1}),s.jsxs(M,{kind:"primary",disabled:e.isPending,children:[!!e.isPending&&s.jsx(N,{inline:!0}),r("action.save")]}),s.jsx($,{to:"/",kind:"tertiary",children:r("action.cancel")})]})]})})}export{V as component};
//# sourceMappingURL=password.change.index-DmMHUzvm.js.map
