import{n as e}from"./chunk-Bh1tDfsg.js";import{n as t,r as n,t as r}from"./password_changes-B_Q5-EtU.js";import{A as i,D as a,Dt as o,Et as s,Mt as c,N as l,O as u,P as d,Tt as f,W as p,ct as m,jt as h,k as g,kt as _,u as v}from"./main-ChC-SNZa.js";import{t as y}from"./Separator-BgSf8Vu2.js";import"./Separator-BRiwsd7J.js";import{t as b}from"./ButtonLink-CvJOjYPg.js";var x=e(c()),S=h(),C=i(`
  mutation ChangePassword(
    $userId: ID!
    $oldPassword: String!
    $newPassword: String!
  ) {
    setPassword(
      input: {
        userId: $userId
        currentPassword: $oldPassword
        newPassword: $newPassword
      }
    ) {
      status
    }
  }
`);function w(){let{t:e}=d(),{data:{viewer:i,siteConfig:c}}=_(v),h=f();if(i.__typename!==`User`)throw s();let w=i.id,T=(0,x.useRef)(null),E=o({async mutationFn(e){let t=e.get(`current_password`),n=e.get(`new_password`);if(n!==e.get(`new_password_again`))throw Error(`passwords mismatch; this should be checked by the form`);let r=await g({query:C,variables:{userId:w,oldPassword:t,newPassword:n}});return r.setPassword.status===`ALLOWED`&&h.navigate({to:`/password/change/success`}),r.setPassword}}),D=async e=>{e.preventDefault();let t=new FormData(e.currentTarget);E.mutate(t)},O=E.error!==null,k=r(e,E.data?.status);return(0,S.jsx)(u,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,S.jsx)(l,{Icon:n,title:e(`frontend.password_change.title`),subtitle:e(`frontend.password_change.subtitle`)}),(0,S.jsxs)(p.Root,{onSubmit:D,method:`POST`,children:[O&&(0,S.jsx)(m,{type:`critical`,title:e(`frontend.password_change.failure.title`),children:e(`frontend.password_change.failure.description.unspecified`)}),k!==void 0&&(0,S.jsx)(m,{type:`critical`,title:e(`frontend.password_change.failure.title`),children:k}),(0,S.jsxs)(p.Field,{name:`current_password`,serverInvalid:E.data?.status===`WRONG_PASSWORD`,children:[(0,S.jsx)(p.Label,{children:e(`frontend.password_change.current_password_label`)}),(0,S.jsx)(p.PasswordControl,{required:!0,autoComplete:`current-password`,ref:T}),(0,S.jsx)(p.ErrorMessage,{match:`valueMissing`,children:e(`frontend.errors.field_required`)}),E.data&&E.data.status===`WRONG_PASSWORD`&&(0,S.jsx)(p.ErrorMessage,{children:e(`frontend.password_change.failure.description.wrong_password`)})]}),(0,S.jsx)(y,{}),(0,S.jsx)(t,{siteConfig:c,forceShowNewPasswordInvalid:E.data&&E.data.status===`INVALID_NEW_PASSWORD`||!1}),(0,S.jsxs)(p.Submit,{kind:`primary`,disabled:E.isPending,children:[!!E.isPending&&(0,S.jsx)(a,{inline:!0}),e(`action.save`)]}),(0,S.jsx)(b,{to:`/`,kind:`tertiary`,children:e(`action.cancel`)})]})]})})}export{w as component};
//# sourceMappingURL=password.change.index-fsNXtBe7.js.map