import{Cr as e,fr as t,gr as n,hr as r,o as i}from"./axios-v6FV69Ne.js";import{i as a,s as o,t as s}from"./ctiAxios-BIVP6fGU.js";import{t as c}from"./useMutation-Dw_VO9_w.js";import{n as l}from"./favoritesAdapter-CNcc7nNe.js";var u=t=>{let i=t.getElementsByTagName(`HTTP_SERVICE`)[0],a=r(i,`PROFILE`),o=[];return a&&a.length&&a.forEach((t,i)=>{let a=n(t),s={};Object.entries(a).forEach(e=>{e[1]===`true`?s[e[0]]=!0:e[1]===`false`?s[e[0]]=!1:s[e[0]]=e[1]}),s.auths=e(r(t,`AUT`));let c=r(t,`FAVORITE`)[0];s.favorites=[],c&&(s.favorites=l(c,!0)),s.key=i,o.push(s)}),o},d=t=>{let i=t.getElementsByTagName(`HTTP_SERVICE`)[0],a=r(i,`MODULES`)[0],o=r(i,`SECURITY_LEVEL`)[0],s=r(i,`CTIUSRDIR`)[0],c=r(a,`MODULE`),l=[];return c&&c.length&&c.forEach((t,i)=>{let a=n(t),o=r(t,`VIEW`),s=[];o&&o.length&&(s=e(o)),a.views=s,a.key=i,l.push(a)}),{modules:l,securityLevels:e(r(o,`RECORD`)),envs:e(r(s,`ENVIRONMENT`)),ctiusrdir:n(s)}},f=async()=>u(await a(`modules/outils/php/getUsers.php`)),p=async()=>d(await a(`modules/outils/php/httpService_usersManager_getConfig.php`)),m=async(e,t)=>{await a(`modules/outils/php/setUser.php`,{option:`save`,file:t,recordXML:e})},h=async(e,t)=>{await a(`modules/outils/php/setUser.php`,{option:`delete`,file:t,recordXML:e})},g=async(e,n)=>{let r={...n};r.theme=r.theme===!0?`light`:`dark`;let i=new FormData;i.append(`user`,e),i.append(`displaySettings`,JSON.stringify(r));let a=await s({method:`post`,url:t()+`modules/outils/php/httpService_usersManager_updateUserDisplaySettings.php`,data:i,headers:{"Content-Type":`multipart/form-data`}}),o=typeof a.data==`string`?a.data:new TextDecoder().decode(a.data);if(o.startsWith(`KO`))throw Error(o.substring(3))},_=async(e,t,r)=>{let i=(await a(`modules/outils/php/httpService_passwordManager_update.php`,{user:e,password:t,newPassword:r})).getElementsByTagName(`HTTP_SERVICE`)[0],o=n(i);if(o.returnCode!==`OK`)throw Error(o.returnTexte);return o},v={all:[`users`],list:()=>[...v.all,`list`],modules:()=>[...v.all,`modules`]};function y(){let e=i();return c({mutationFn:({userXml:e,file:t})=>m(e,t),meta:{successMessage:`Utilisateur enregistré`,errorMessage:`Erreur lors de l'enregistrement de l'utilisateur`},onSettled:async()=>{await e.invalidateQueries({queryKey:v.list()})}})}function b(){let e=i();return c({mutationFn:({userXml:e,file:t})=>h(e,t),meta:{successMessage:`Utilisateur supprimé`,errorMessage:`Erreur lors de la suppression de l'utilisateur`},onSettled:async()=>{await e.invalidateQueries({queryKey:v.list()})}})}function x(){let e=i();return c({mutationFn:({user:e,displaySettings:t})=>g(e,t),meta:{successMessage:`Préférences enregistrées`,errorMessage:`Erreur lors de la mise à jour des préférences`},onMutate:async({displaySettings:t})=>{await e.cancelQueries({queryKey:o.all});let n=e.getQueryData(o.all),{primaryColor:r,...i}=t;return e.setQueryData(o.all,e=>({...e,user:{...e?.user,...i},...r!==void 0&&{primaryColor:r}})),{previousSettings:n}},onError:(t,n,r)=>{r?.previousSettings&&e.setQueryData(o.all,r.previousSettings)},onSettled:async()=>{await e.invalidateQueries({queryKey:o.all})}})}function S(){return c({mutationFn:({user:e,password:t,newPassword:n})=>_(e,t,n),meta:{successMessage:`Mot de passe modifié`,errorMessage:`Erreur lors de la mise à jour du mot de passe`}})}export{v as a,x as i,y as n,p as o,S as r,f as s,b as t};