import{_ as ne}from"./Imprimer-CqTc6qE9.js";import{_ as ie}from"./ComboDynamique-CzrtYPe1.js";import{u as re,a as g,s,S as h,g as ue}from"./index-Bn9WoKhP.js";import{r as a,f as de,o as p,c as E,b as l,i as _,z as ce,d as f,j as R,a as u,av as pe,M as me,an as fe,ap as ve,q as be,F as ge,ar as _e,e as U}from"./vendor-0kGcmQpG.js";import{_ as ye}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const je={key:0},we={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},xe={class:"w-full bg-white p-4"},$e={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},De={class:"flex flex-col gap-2"},he={class:"mb-3"},ke={class:"p-float-label"},Ce={class:"mb-3"},Ie={class:"p-float-label"},Pe={class:"mb-3"},Ve={class:"p-float-label"},Ae={class:"flex flex-col gap-2"},Me={class:"field"},Fe={class:"p-float-label"},Te={class:"field"},Ee={class:"w-full flex flex-row items-center gap-3 p-2"},Re={style:{height:"calc(100vh - 180px)"}},qe={__name:"Projets",props:{ndoc:{type:String,default:""}},setup(S){const{showError:v,showInfo:k,showWarn:L}=re(),C=S,j=a(),b=a(),B=a([]),n=a({}),z=a(null),y=a([]),m=a(!1),w=a(null),d=a(!1),c=a(!1),N=a(!1),x=a(!1),G=a(""),q=a(""),$=a(C.ndoc||""),I=a(null),P=a(null),r=_e({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),O=({event:t,ndoc:e,rowIndex:i})=>{$.value=e,w.value=i,A()},W=({selectedRows:t})=>{B.value=t,z.value=t.length>0?t[0]:null},H=t=>{b.value=t.api},J=[{label:"Ajouter",icon:"pi pi-plus-circle",command:()=>V(),disabled:U(()=>!r.ajout)},{label:"Supprimer",icon:"pi pi-trash",command:()=>se(),disabled:U(()=>!r.supp)}],K=[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>te()},{label:"Imprimer la liste",icon:"pi pi-print",command:()=>le()}];de(async()=>{await Q(),$.value?(A(),d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)):D()});const Q=async()=>{try{const e=(await g.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:901,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(r.lecture=e.lecture,r.ajout=e.ajout,r.modif=e.modif,r.supp=e.supp,r.devalidation=e.devalidation,r.validation=e.validation),r.lecture||(L("Vous n'avez pas le droit, veuillez consulter l'administrateur"),h("Projets"))}catch(t){v("Une erreur s'est produite lors de la vérification des droits."+t)}},D=async()=>{s.state.afficher_in_progress=!0;try{m.value=!1,G.value=q.value;const t=await g.post(`${s.lienApi}/projets/${s.db}`,{},{headers:{"Content-Type":"application/json"}});y.value=t.data}catch(t){v(`Une erreur est survenue lors de l'affichage des données. ${t}`)}finally{s.state.afficher_in_progress=!1}},V=async()=>{try{const t=await g.post(`${s.lienApi}/ajouterEtRenvoyerProjet/${s.db}`);n.value=t.data,m.value=!0,d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)}catch(t){v(`Une erreur est survenue lors de l'ajout du projet. ${t}`)}finally{s.state.afficher_in_progress=!1}},X=async()=>{d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)},Y=async()=>{try{const t=`${s.lienApi}/enregistrerProjets/${s.db}/${n.value.IdProjet}`;await g.post(t,n.value,{headers:{"Content-Type":"application/json"}}),d.value=!1,c.value=!1}catch(t){const e=t.response?.data?.message||t.message;v(`Une erreur est survenue : 
 ${e}`)}finally{s.state.afficher_in_progress=!1}},Z=()=>{d.value=!1,c.value=!1},ee=()=>{C.ndoc?h("Projets"):(m.value=!1,D(),w.value!=null&&b.value&&setTimeout(()=>{const t=b.value.getDisplayedRowCount();if(t>0){const e=Math.min(w.value,t-1),i=b.value.getDisplayedRowAtIndex(e);i&&(b.value.deselectAll(),i.setSelected(!0),b.value.ensureNodeVisible(i,"middle"))}},100))},te=()=>{if(!j.value){k("Grille non initialisée");return}if(y.value.length===0){k("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");j.value.exportToExcel(`Liste des projets_${s.state.enreg_societe.Nom}_${e}.xlsx`)},le=()=>{x.value=!0},A=async()=>{try{const t=await g.post(`${s.lienApi}/unProjet/${s.db}/${$.value}`);n.value=t.data,m.value=!0}catch(t){v(`Une erreur est survenue lors de l'affichage des détails du projet.
 ${t}`)}finally{s.state.afficher_in_progress=!1}},se=async()=>{try{const t=`${s.lienApi}/supprimerProjets/${s.db}/${n.value.IdProjet}`;await g.post(t),m.value=!1,d.value=!1,N.value=!1,D()}catch(t){const e=t.response?.data?.message||t.message;v(`Une erreur est survenue :
 ${e}`)}};return(t,e)=>{const i=ce,M=pe,F=me,T=ue,oe=ie,ae=ne;return p(),E(ge,null,[m.value&&r.lecture?(p(),E("div",je,[l("div",we,[c.value?f("",!0):(p(),_(i,{key:0,icon:"pi pi-pencil",label:"Modifier",text:"",onClick:e[0]||(e[0]=o=>X()),disabled:!r.modif},null,8,["disabled"])),c.value?f("",!0):(p(),_(M,{key:1,ref_key:"actionsMenu",ref:I,model:J,popup:!0},{button:R(()=>[u(i,{icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=o=>I.value.toggle(o))})]),_:1},512)),c.value?f("",!0):(p(),_(i,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:ee})),c.value?(p(),_(i,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=o=>Y())})):f("",!0),c.value?(p(),_(i,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=o=>Z())})):f("",!0)]),l("div",xe,[l("div",$e,[l("div",De,[l("div",he,[l("span",ke,[e[13]||(e[13]=l("label",{for:"idProjet"},"Numéro",-1)),u(F,{size:"small",id:"idProjet",modelValue:n.value.IdProjet,"onUpdate:modelValue":e[4]||(e[4]=o=>n.value.IdProjet=o),class:"w-full",disabled:""},null,8,["modelValue"])])]),l("div",Ce,[l("span",Ie,[e[14]||(e[14]=l("label",{for:"inputFocus"},"Libellé",-1)),u(F,{size:"small",id:"inputFocus",modelValue:n.value.Libelle,"onUpdate:modelValue":e[5]||(e[5]=o=>n.value.Libelle=o),class:"w-full",disabled:!d.value},null,8,["modelValue","disabled"])])]),l("div",Pe,[l("span",Ve,[e[15]||(e[15]=l("label",{for:"dateDebut"},"Date Début",-1)),u(T,{size:"small",id:"dateDebut",modelValue:n.value.DateDebut,"onUpdate:modelValue":e[6]||(e[6]=o=>n.value.DateDebut=o),"input-class":"w-full",disabled:!d.value},null,8,["modelValue","disabled"])])])]),l("div",Ae,[l("div",Me,[l("span",Fe,[e[16]||(e[16]=l("label",{for:"dateFin"},"Date Fin",-1)),u(T,{size:"small",id:"dateFin",modelValue:n.value.DateFin,"onUpdate:modelValue":e[7]||(e[7]=o=>n.value.DateFin=o),"input-class":"w-full",disabled:!d.value},null,8,["modelValue","disabled"])])]),l("div",Te,[e[17]||(e[17]=l("label",{for:"commercial"},"Commercial",-1)),u(oe,{id:"responsable",modelValue:n.value.IDcommercial,"onUpdate:modelValue":e[8]||(e[8]=o=>n.value.IDcommercial=o),placeholder:"Responsable",table:"commercial",enabled:d.value,class:"w-full"},null,8,["modelValue","enabled"])])])])])])):f("",!0),fe(l("div",null,[l("div",Ee,[u(i,{icon:"pi pi-plus-circle",label:"Ajouter",text:"",onClick:e[9]||(e[9]=o=>V()),disabled:!r.ajout},null,8,["disabled"]),u(M,{ref_key:"listeMenu",ref:P,model:K,popup:!0},{button:R(()=>[u(i,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[10]||(e[10]=o=>P.value.toggle(o))})]),_:1},512),u(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[11]||(e[11]=o=>be(h)("Projets"))})]),l("div",Re,[u(ye,{ref_key:"dataGrid",ref:j,"excel-file-name":"Projets","excel-sheet-name":"Projets","row-data":y.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{IdProjet:150,Libelle:300,DateDebut:150,DateFin:150,responsable:200},"date-only":["Date"],"enable-totals":!1,"show-checkbox":!1,"numeric-columns":[],onRowClicked:O,onSelectionChanged:W,onGridReady:H},null,8,["row-data"])])],512),[[ve,!m.value&&r.lecture]]),x.value?(p(),_(ae,{key:1,data:y.value,showModelSelector:!0,listeModelType:"Liste des projets",modeList:!0,onClose:e[12]||(e[12]=o=>x.value=!1)},null,8,["data"])):f("",!0)],64)}}};export{qe as default};
