import{u as x,p as S,q as y,ab as j,s as I,r as b,d as R,m as l,l as w,j as s,L as q,P as C,R as v,M as u,F as A,g as D,J as E,K as c,i as O}from"./main-BiT4j4N5.js";import{t as L,I as N,P as W}from"./password_changes-g3oE0t0I.js";import{S as F}from"./Submit-fS0aoNPD.js";import{B as M}from"./ButtonLink-MFNyI4rM.js";import{S as $}from"./Separator-Bb4mxhob.js";import"./_commonjsHelpers-DaWZu8wl.js";/* empty css               */const k=w(`
  mutation ChangePassword(
    $userId: ID!
    $oldPassword: String!
    $newPassword: String!
  ) {
    setPassword(
      input: {
        userId: $userId
        currentPassword: $oldPassword
        newPassword: $newPassword
      }
    ) {
      status
    }
  }
`),T=w(`
  query PasswordChange {
    viewer {
      __typename
      ... on Node {
        id
      }
    }

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