import{aD as u,an as l,ap as m,ao as c,aH as d,x as p,av as h,k as x,cV as j,j as t,am as U,r as v,l as f,a5 as F,aC as S,T as i}from"./main-TIUJvpaR.js";import{D as y,b as C}from"./crupdate-resource-layout-CYzZacgj.js";import{u as b}from"./use-normalized-models-DEvVtvvO.js";import{F as E}from"./form-chip-field-ebQy8_UE.js";function g(r,e){const a=u();return l({mutationFn:s=>w(r,s),onSuccess:()=>{d(p("User updated")),h.invalidateQueries({queryKey:["users"]}),a("../..",{relative:"path"})},onError:s=>e?m(s,e):c(s)})}function w(r,e){return e.roles&&(e.roles=e.roles.map(a=>a.id)),x.put(`users/${r}`,e).then(a=>a.data)}function I({form:r,children:e}){const a=j(),s=g(a.id,r);return t.jsxs(U,{onSubmit:n=>{s.mutate(n)},onBeforeSubmit:()=>r.clearErrors(),form:r,children:[e,t.jsx(y,{isLoading:s.isPending})]})}function N({endpoint:r}){const[e,a]=v.useState(""),{data:s}=b(r??"normalized-models/role",{query:e}),{hasPermission:n}=f();return t.jsx(C,{label:t.jsx(i,{message:"Roles"}),children:t.jsx(E,{className:"mb-30",name:"roles",suggestions:s==null?void 0:s.results,inputValue:e,onInputValueChange:a,alwaysShowAvatar:!0,readOnly:!n("users.update"),description:t.jsx(i,{message:"User will inherit all permissions from the roles they are assigned."}),children:o=>t.jsx(F,{value:o.id,startIcon:t.jsx(S,{label:o.name}),children:o.name},o.id)})})}export{I as U,N as a};
