import{j as r,S as m}from"./vendor-ClLR6ncd.js";import{n as q,T as p,aT as g,q as k,d as v,i as h,as as N,ar as s}from"./index-OtVJl4GC.js";import{C as A}from"./CheckboxWithLabel-D5KtBcIx.js";import{u as M}from"./model-DfaTiZQD.js";import{D as T}from"./Divider-DZzUGEvZ.js";import"./lodash-ZyeDnt0e.js";import{b as R,a as D,f as O,c as V}from"./useEntity-C2GgsMNR.js";function H({label:e="New password",error:u,username:t,helperText:o,disabled:n=!1}){const{isInvalidInput:d,buildErrorMessage:a,setNewPassword:i,currentPassword:l,setCurrentPassword:b,newPassword:P,repeatPassword:C,setRepeatPassword:E,resetPasswords:I,externalAuthentication:c,setExternalAuthentication:Q,isSuperuserChangeOwnPassword:j}=M(),{value:S}=q(),f=n||c,x=c?!1:t!==g;return r.jsxs(m,{direction:"row",alignItems:"center",divider:r.jsx(T,{flexItem:!0,orientation:"vertical"}),spacing:1,children:[r.jsxs(m,{flexGrow:1,spacing:S?0:1,children:[j(t)&&r.jsx(p,{required:!0,type:"password",autoComplete:"current-password",value:l,setter:b,label:"Current password",error:u,helperText:o}),r.jsx(p,{disabled:f,required:x,type:"password",autoComplete:"new-password",label:e,value:P,setter:i}),r.jsx(p,{disabled:f,required:x,type:"password",autoComplete:"new-password",label:"Repeat password",value:C,setter:E,error:d(t),helperText:a(t)})]}),r.jsx(A,{label:"External authentication",value:c,setter:U=>{Q(U),I()}})]})}const W=[{urlSuffix:"roles",key:"roles"},{urlSuffix:"suspended",key:"suspended"},{urlSuffix:"enabled",key:"enabled"},{urlSuffix:"password/expired",key:"isExpiredPassword"},...V];function y(e){return{queryKey:["admin","user",e],queryFn:()=>O(e,"username","users",W)}}const J=R(y),X=D(y,"/users"),w=e=>{s.invalidateQueries(["admin","user",e]),s.invalidateQueries([e,"users","attributes"]),s.invalidateQueries([e,"users","color"]),s.invalidateQueries(["current-user-color"])},$=e=>{s.removeQueries(["admin","user",e]),s.removeQueries([e,"users","attributes"]),s.removeQueries([e,"users","color"]),s.resetQueries(["admin","/users"])},Y=(e,u,t,o,n)=>{const{signin:d}=k();return v(async()=>{try{await h({method:"post",url:`/users/${e}/password`,data:t,...o?{auth:{username:e,password:u}}:{}})}catch(a){throw a instanceof N?new Error("Incorrect current password"):a}},{onSuccess:(a,{username:i,newPassword:l})=>{o&&d({username:i,password:l}),w(i),n()}})},Z=e=>v(()=>h({method:"put",url:`/users/${e}/password/expired`}),{onSuccess:()=>{w(e)}}),ee={urlPrefix:"/users",invalidate:w,remove:$};export{H as N,Y as a,Z as b,J as c,ee as d,w as i,X as u};
