import{n as e}from"./chunk-DrgAwqJ9.js";import{i as t,s as n,t as r}from"./graphql-BME5mLgf.js";import{n as i,t as a}from"./LoadingSpinner-BR8GsFxa.js";import{n as o,t as s}from"./jsx-runtime-C3uB2UIS.js";import{t as c}from"./useRouter-CHCc-Qju.js";import"./useStore-BnK_t0Uy.js";import{n as l}from"./not-found-D2Q6nITs.js";import"./link-DiTuM_g9.js";import{t as u}from"./useTranslation-DVVidJl_.js";import{a as d,o as f,s as p,t as m}from"./Message-C3OrPzh0.js";import{n as h,r as g,t as _}from"./password_changes-UOY4wXZy.js";import{t as v}from"./Submit-CmO9RMCD.js";import{t as y}from"./Password-DFm2ysf4.js";import{C as b,S as x,T as S,c as C}from"./main-BpPO1zAy.js";import{t as w}from"./Separator-DAu78SgA.js";import"./Separator-C1w3hBbl.js";import{t as T}from"./ButtonLink-BlaAAQga.js";var E=e(o()),D=s(),O=t(`
  mutation ChangePassword(
    $userId: ID!
    $oldPassword: String!
    $newPassword: String!
  ) {
    setPassword(
      input: {
        userId: $userId
        currentPassword: $oldPassword
        newPassword: $newPassword
      }
    ) {
      status
    }
  }
`);function k(){let{t:e}=u(),{data:{viewer:t,siteConfig:o}}=n(C),s=c();if(t.__typename!==`User`)throw l();let k=t.id,A=(0,E.useRef)(null),j=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:O,variables:{userId:k,oldPassword:t,newPassword:n}});return i.setPassword.status===`ALLOWED`&&s.navigate({to:`/password/change/success`}),i.setPassword}}),M=async e=>{e.preventDefault();let t=new FormData(e.currentTarget);j.mutate(t)},N=j.error!==null,P=_(e,j.data?.status);return(0,D.jsx)(x,{children:(0,D.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,D.jsx)(b,{Icon:g,title:e(`frontend.password_change.title`),subtitle:e(`frontend.password_change.subtitle`)}),(0,D.jsxs)(d,{onSubmit:M,method:`POST`,children:[N&&(0,D.jsx)(S,{type:`critical`,title:e(`frontend.password_change.failure.title`),children:e(`frontend.password_change.failure.description.unspecified`)}),P!==void 0&&(0,D.jsx)(S,{type:`critical`,title:e(`frontend.password_change.failure.title`),children:P}),(0,D.jsxs)(p,{name:`current_password`,serverInvalid:j.data?.status===`WRONG_PASSWORD`,children:[(0,D.jsx)(f,{children:e(`frontend.password_change.current_password_label`)}),(0,D.jsx)(y,{required:!0,autoComplete:`current-password`,ref:A}),(0,D.jsx)(m,{match:`valueMissing`,children:e(`frontend.errors.field_required`)}),j.data&&j.data.status===`WRONG_PASSWORD`&&(0,D.jsx)(m,{children:e(`frontend.password_change.failure.description.wrong_password`)})]}),(0,D.jsx)(w,{}),(0,D.jsx)(h,{siteConfig:o,forceShowNewPasswordInvalid:j.data&&j.data.status===`INVALID_NEW_PASSWORD`||!1}),(0,D.jsxs)(v,{kind:`primary`,disabled:j.isPending,children:[!!j.isPending&&(0,D.jsx)(a,{inline:!0}),e(`action.save`)]}),(0,D.jsx)(T,{to:`/`,kind:`tertiary`,children:e(`action.cancel`)})]})]})})}export{k as component};
//# sourceMappingURL=password.change.index-DS4PiI_q.js.map