import{r as o,f as b,j as s,S as d,h,H as x,s as v}from"./vendor-ClLR6ncd.js";import{D as y}from"./index-DY-IkI-n.js";import{T as i}from"./index-OtVJl4GC.js";import{u as T,a as N}from"./model-B67jE2jA.js";import"./DialogContent-DR8Wx7Lo.js";import"./DialogTitle-i0lt2jWQ.js";import"./lodash-ZyeDnt0e.js";const I=()=>{};function U(){const a=T(),[u,f]=o.useState(""),e=N(),[r,p]=o.useState(""),[n,c]=o.useState(""),[t,l]=o.useState(""),j=r!==""&&r===n&&t!==r&&t!=="",w=n!==""&&r!==n,m=t!==""&&r!==""&&t===r,C=b(),g=()=>{C(-1)},P=e.isIdle?I:g,S=o.useCallback(()=>{e.mutate({username:a||u,currentPassword:t,newPassword:r})},[t,r,e,a,u]);return s.jsx(y,{isOpen:!0,isDisabledSubmit:!j||e.isLoading||e.isError||e.isSuccess,cancel:g,close:P,dialogTitle:a?`Change password for ${a}`:"Your password is expired. You need to change it",dialogBodyMessage:e.isIdle?s.jsxs(d,{spacing:1,children:[a?null:s.jsx(i,{required:!0,type:"text",autoComplete:"username",value:u,setter:f,label:"Username"}),s.jsx(i,{required:!0,type:"password",autoComplete:"current-password",value:t,setter:l,label:"Current password"}),s.jsx(i,{required:!0,error:m,helperText:m?"New password must differ from the current one":"",type:"password",autoComplete:"new-password",value:r,setter:p,label:"New password"}),s.jsx(i,{required:!0,type:"password",autoComplete:"off",error:w,helperText:w?"New passwords inputs aren't the same":void 0,value:n,setter:c,label:"Repeat new password"})]}):e.isLoading?"Changing password...":e.isError?s.jsxs(d,{spacing:2,children:[s.jsxs(h,{children:["Error on changing password: ",e.error.message]}),s.jsx(x,{variant:"contained",onClick:()=>{l(""),p(""),c(""),e.reset()},children:"Try again"})]}):e.isSuccess?s.jsxs(d,{spacing:2,children:[s.jsx(h,{children:"Password is changed successfully!"}),s.jsx(x,{variant:"contained",component:v,to:"/",children:"Go to Home page"})]}):"",submitTitle:"Change",onSubmit:S})}export{U as default};
