import{b as z,g as R,f as S}from"./primevue-CfIk0_DY.js";import{_ as L,u as O,s as o,b as f}from"./index-BxIwIJfy.js";import{a1 as P,w as C,o as j,i as H,b as v,k as q,l as w,c as x,d as a,q as J,v as d,j as k,p as G,F as N,a as g}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const K={key:0,class:"profil-grid"},Q={class:"profil-photo"},W=["src","title"],X={class:"profil-photo__actions"},Y={class:"profil-champs"},Z={class:"field"},ee={class:"field"},se={__name:"MonCompte",props:{show:Boolean},emits:["close"],setup(U,{emit:E}){const{showError:h,showInfo:M}=O(),y=U,I=E,D=P(),i=g(!1),l=g(),c=g(!1),m=g("");C(()=>y.show,s=>{c.value=s}),C(()=>c.value,s=>{s||I("close")}),j(async()=>{c.value=y.show,l.value=o.state.userCloud,l.value||D.push({path:"/"});const s=await b();m.value=s||"/images/profile.png"});let _=null;const V=()=>{_={Nom:l.value?.Nom},i.value=!0},A=()=>{_&&l.value&&(l.value.Nom=_.Nom),i.value=!1},B=async()=>{const{IDutilisateur:s,IdClients:e,mail:t,Nom:p}=l.value,n={IDutilisateur:s,IdClients:e,mail:t,Nom:p};try{(await f.post(`${o.lienApi}/update_utilisateur_cloud/${o.state.userCloud.IDutilisateur}`,{monJson:n,IdClients:e},{headers:{"Content-Type":"application/json"}})).status===200&&(c.value=!1,M("Compte modifié avec succès",void 0,()=>{c.value=!0,i.value=!1}))}catch(u){const r=u.response?.data?.message||u.message;h("Une erreur est survenue : "+r)}},b=async()=>{try{const s=await f.post(`${o.lienApi}/retourner_un_seulfichier`,{},{headers:{"x-path":`clients/${o.cloudId}/commun6/utilisateur/profile/${o.userId}`}}),e=s.data;if(s.status===404||e.length==0)return"/images/profile.png";const t="?v="+Date.now();return`${o.lienApi}/fichiers_public/clients/${o.cloudId}/commun6/utilisateur/profile/${o.userId}/${e[0]}${t}`}catch{return"/images/profile.png"}},F=async()=>{const s=await b();o.commit("SET_USER_PHOTO_URL",s)},$=()=>{const s=document.createElement("input");s.type="file",s.click(),s.addEventListener("change",async e=>{let t=e.target.files[0];const p=new FormData;p.append("file",t);try{await f.post(`${o.lienApi}/upload_un_fichier`,p,{headers:{"x-custom-filename":`${t.name}`,"x-path":`clients/${o.cloudId}/commun6/utilisateur/profile/${o.userId}`}});const n=await b();m.value=n||"/images/profile.png",await F()}catch(n){const u=n.response?.data?.message||n.message;h("Une erreur est survenue : "+u)}})},T=async()=>{try{await f.post(`${o.lienApi}/deleteFile`,{},{headers:{"x-path":`clients/${o.cloudId}/commun6/utilisateur/profile/${o.userId}`}}),m.value="/images/profile.png",o.commit("SET_USER_PHOTO_URL",null)}catch(s){const e=s.response?.data?.message||s.message;h("Une erreur est survenue : "+e)}finally{o.state.afficher_in_progress=!1}};return(s,e)=>{const t=z,p=R,n=S,u=H("maxlen-db");return v(),q(n,{visible:c.value,"onUpdate:visible":e[5]||(e[5]=r=>c.value=r),style:{width:"560px"},breakpoints:{"640px":"95vw"},modal:!0,draggable:!1,class:"p-dialog-profile"},{header:w(()=>[...e[6]||(e[6]=[a("div",{class:"flex items-center gap-2"},[a("i",{class:"pi pi-user profil-header-icon"}),a("span",{class:"font-semibold"},"Mon compte")],-1)])]),footer:w(()=>[i.value?(v(),x(N,{key:0},[d(t,{label:"Annuler",icon:"pi pi-times",text:"",severity:"secondary",onClick:A}),d(t,{label:"Enregistrer",icon:"pi pi-save",onClick:e[3]||(e[3]=r=>B())})],64)):(v(),x(N,{key:1},[d(t,{label:"Fermer",icon:"pi pi-times",text:"",severity:"secondary",onClick:e[4]||(e[4]=r=>I("close"))}),d(t,{label:"Modifier",icon:"pi pi-pencil",onClick:V})],64))]),default:w(()=>[l.value?(v(),x("div",K,[a("div",Q,[a("img",{src:m.value,alt:"Photo de profil",class:J({"profil-photo--editable":i.value}),title:i.value?"Changer la photo":"",onClick:e[0]||(e[0]=r=>i.value&&$())},null,10,W),a("div",X,[d(t,{icon:"pi pi-camera",text:"",rounded:"",size:"small",onClick:$,disabled:!i.value,title:"Changer la photo"},null,8,["disabled"]),d(t,{icon:"pi pi-trash",text:"",rounded:"",size:"small",severity:"danger",onClick:T,disabled:!i.value,title:"Supprimer la photo"},null,8,["disabled"])])]),a("div",Y,[a("div",Z,[e[7]||(e[7]=a("label",{class:"block mb-1",for:"nom"},"Nom",-1)),k(d(p,{size:"small",id:"nom",modelValue:l.value.Nom,"onUpdate:modelValue":e[1]||(e[1]=r=>l.value.Nom=r),disabled:!i.value,class:"w-full"},null,8,["modelValue","disabled"]),[[u,"utilisateur.Nom"]])]),a("div",ee,[e[8]||(e[8]=a("label",{class:"block mb-1",for:"mail"},"Adresse mail",-1)),k(d(p,{size:"small",id:"mail",modelValue:l.value.mail,"onUpdate:modelValue":e[2]||(e[2]=r=>l.value.mail=r),disabled:"",class:"w-full",title:"L'adresse mail sert d'identifiant de connexion : elle ne se modifie pas ici."},null,8,["modelValue"]),[[u,"utilisateur.mail"]]),e[9]||(e[9]=a("small",{class:"profil-aide"},"Identifiant de connexion — non modifiable.",-1))])])])):G("",!0)]),_:1},8,["visible"])}}},ne=L(se,[["__scopeId","data-v-87c0d341"]]);export{ne as default};
