import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{i as t,s as n,t as r}from"./graphql-w47gyQE9.js";import{n as i,t as a}from"./LoadingSpinner-0XRXvdGq.js";import{n as o,t as s}from"./jsx-runtime-BHz_hoGM.js";import{t as c}from"./useRouter-B9Ekf4jx.js";import{n as l}from"./not-found-i5RsCZif.js";import{t as u}from"./useTranslation-CWZfA4RN.js";import{n as d,r as f,t as p}from"./password_changes-DPV_YyfH.js";import{A as m,D as h,J as g,O as _,u as v}from"./main-CqHK_FoX.js";import{t as y}from"./Separator-K1RKzFV8.js";import"./Separator-CUqwPKvA.js";import{t as b}from"./ButtonLink-BaIKz4k4.js";var x=e(o()),S=s(),C=t(`
  mutation ChangePassword(
    $userId: ID!
    $oldPassword: String!
    $newPassword: String!
  ) {
    setPassword(
      input: {
        userId: $userId
        currentPassword: $oldPassword
        newPassword: $newPassword
      }
    ) {
      status
    }
  }
`);function w(){let{t:e}=u(),{data:{viewer:t,siteConfig:o}}=n(v),s=c();if(t.__typename!==`User`)throw l();let w=t.id,T=(0,x.useRef)(null),E=i({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 i=await r({query:C,variables:{userId:w,oldPassword:t,newPassword:n}});return i.setPassword.status===`ALLOWED`&&s.navigate({to:`/password/change/success`}),i.setPassword}}),D=async e=>{e.preventDefault();let t=new FormData(e.currentTarget);E.mutate(t)},O=E.error!==null,k=p(e,E.data?.status);return(0,S.jsx)(h,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,S.jsx)(_,{Icon:f,title:e(`frontend.password_change.title`),subtitle:e(`frontend.password_change.subtitle`)}),(0,S.jsxs)(m.Root,{onSubmit:D,method:`POST`,children:[O&&(0,S.jsx)(g,{type:`critical`,title:e(`frontend.password_change.failure.title`),children:e(`frontend.password_change.failure.description.unspecified`)}),k!==void 0&&(0,S.jsx)(g,{type:`critical`,title:e(`frontend.password_change.failure.title`),children:k}),(0,S.jsxs)(m.Field,{name:`current_password`,serverInvalid:E.data?.status===`WRONG_PASSWORD`,children:[(0,S.jsx)(m.Label,{children:e(`frontend.password_change.current_password_label`)}),(0,S.jsx)(m.PasswordControl,{required:!0,autoComplete:`current-password`,ref:T}),(0,S.jsx)(m.ErrorMessage,{match:`valueMissing`,children:e(`frontend.errors.field_required`)}),E.data&&E.data.status===`WRONG_PASSWORD`&&(0,S.jsx)(m.ErrorMessage,{children:e(`frontend.password_change.failure.description.wrong_password`)})]}),(0,S.jsx)(y,{}),(0,S.jsx)(d,{siteConfig:o,forceShowNewPasswordInvalid:E.data&&E.data.status===`INVALID_NEW_PASSWORD`||!1}),(0,S.jsxs)(m.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-CKPqfuAr.js.map