import{K as S,w as C,f as B,C as I,o as m,i as v,j as c,b as l,z as O,h as g,d as w,a as p,c as R,M as j,S as z,r as b}from"./vendor-0kGcmQpG.js";import{u as F,s as o,a as _}from"./index-Bn9WoKhP.js";const L={class:"bg-gray-50 p-3"},P={class:"container mx-auto"},H={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},J={key:0,class:"w-full bg-white border p-3"},K={class:"flex gap-7"},q={class:"img-profile w-1/2"},G={class:"max-w-40"},Q=["src"],W={class:"flex flex-col gap-3 w-full"},X={class:"p-float-label"},Y={class:"p-float-label"},Z={class:"p-float-label"},le={__name:"MonCompte",props:{show:Boolean},emits:["close"],setup(U,{emit:k}){const{showError:x,showInfo:V}=F(),$=U,h=k,E=S(),r=b(!1),a=b(),d=b(!1),f=b("");C(()=>$.show,s=>{d.value=s}),C(()=>d.value,s=>{s||h("close")}),B(async()=>{d.value=$.show,a.value=o.state.userCloud,a.value?a.value.pw_web=I.AES.decrypt(a.value.pw_web,"dVrnTKOLj").toString(I.enc.Utf8):E.push({path:"/"});const s=await y();f.value=s||"/images/profile.png"});const N=async()=>{const{IDutilisateur:s,IdClients:e,mail:i,Nom:n}=a.value,u={IDutilisateur:s,IdClients:e,mail:i,Nom:n};try{(await _.post(`${o.lienApi}/update_utilisateur_cloud/${o.state.userCloud.IDutilisateur}`,{monJson:u,IdClients:e},{headers:{"Content-Type":"application/json"}})).status===200&&(d.value=!1,V("Compte modifié avec succès",void 0,()=>{d.value=!0,r.value=!1}))}catch(t){const D=t.response?.data?.message||t.message;x("Une erreur est survenue : "+D)}},y=async()=>{try{const s=await _.post(`${o.lienApi}/retourner_un_seulfichier`,{},{headers:{"x-path":`clients/${o.cloudId}/commun6/utilisateur/profile/${a.value.mail}`}}),e=s.data;if(s.status===404||e.length==0)return"/images/profile.png";const i="?v="+Date.now();return`${o.lienApi}/fichiers_public/clients/${o.cloudId}/commun6/utilisateur/profile/${a.value.mail}/${e[0]}${i}`}catch{return"/images/profile.png"}},M=async()=>{const s=await y();o.commit("SET_USER_PHOTO_URL",s)},T=()=>{const s=document.createElement("input");s.type="file",s.click(),s.addEventListener("change",async e=>{let i=e.target.files[0];const n=new FormData;n.append("file",i);try{await _.post(`${o.lienApi}/upload_un_fichier`,n,{headers:{"x-custom-filename":`${i.name}`,"x-path":`clients/${o.cloudId}/commun6/utilisateur/profile/${a.value.mail}`}});const u=await y();f.value=u||"/images/profile.png",await M()}catch(u){const t=u.response?.data?.message||u.message;x("Une erreur est survenue : "+t)}})},A=async()=>{try{await _.post(`${o.lienApi}/deleteFile`,{},{headers:{"x-path":`clients/${o.cloudId}/commun6/utilisateur/profile/${a.value.mail}`}}),f.value="/images/profile.png",o.commit("SET_USER_PHOTO_URL",null)}catch(s){const e=s.response?.data?.message||s.message;x("Une erreur est survenue : "+e)}finally{o.state.afficher_in_progress=!1}};return(s,e)=>{const i=O,n=j,u=z;return m(),v(u,{visible:d.value,"onUpdate:visible":e[7]||(e[7]=t=>d.value=t),style:{width:"950px"},modal:!0,closable:!1,draggable:!1,class:"p-dialog-profile"},{default:c(()=>[l("div",L,[l("div",P,[l("div",H,[r.value?w("",!0):(m(),v(i,{key:0,onClick:e[0]||(e[0]=t=>r.value=!0),text:""},{default:c(()=>[...e[8]||(e[8]=[l("i",{class:"pi pi-pencil text-lg mr-2"},null,-1),g(" Modifier ",-1)])]),_:1})),r.value?(m(),v(i,{key:1,onClick:e[1]||(e[1]=t=>N()),text:""},{default:c(()=>[...e[9]||(e[9]=[l("i",{class:"pi pi-save mr-2"},null,-1),g(" Enregistrer ",-1)])]),_:1})):w("",!0),r.value?(m(),v(i,{key:2,onClick:e[2]||(e[2]=t=>r.value=!1),text:""},{default:c(()=>[...e[10]||(e[10]=[l("i",{class:"pi pi-times mr-2"},null,-1),g(" Annuler ",-1)])]),_:1})):w("",!0),p(i,{onClick:e[3]||(e[3]=t=>h("close")),text:"",severity:"danger"},{default:c(()=>[...e[11]||(e[11]=[l("i",{class:"pi pi-times mr-2"},null,-1),g(" Fermer ",-1)])]),_:1})]),a.value?(m(),R("div",J,[l("div",K,[l("div",q,[p(i,{icon:"pi pi-pencil",severity:"success",text:"",onClick:T,disabled:!r.value,class:"profile-action-btn"},null,8,["disabled"]),p(i,{icon:"pi pi-trash",severity:"danger",text:"",onClick:A,disabled:!r.value,class:"profile-action-btn"},null,8,["disabled"]),l("div",G,[l("img",{class:"w-full max-w-40 rounded-lg border",src:f.value,alt:"Photo de profil"},null,8,Q)])]),l("div",W,[l("span",X,[e[12]||(e[12]=l("label",{for:"nom"},"Nom",-1)),p(n,{size:"small",id:"nom",modelValue:a.value.Nom,"onUpdate:modelValue":e[4]||(e[4]=t=>a.value.Nom=t),disabled:!r.value,class:"w-full"},null,8,["modelValue","disabled"])]),l("span",Y,[e[13]||(e[13]=l("label",{for:"tel"},"Téléphone",-1)),p(n,{size:"small",id:"tel",modelValue:a.value.tel,"onUpdate:modelValue":e[5]||(e[5]=t=>a.value.tel=t),disabled:!r.value,class:"w-full"},null,8,["modelValue","disabled"])]),l("span",Z,[e[14]||(e[14]=l("label",{for:"mail"},"Adresse mail",-1)),p(n,{size:"small",id:"mail",modelValue:a.value.mail,"onUpdate:modelValue":e[6]||(e[6]=t=>a.value.mail=t),disabled:"",class:"w-full"},null,8,["modelValue"])])])])])):w("",!0)])])]),_:1},8,["visible"])}}};export{le as default};
