import{_ as ge}from"./Imprimer-DluCFs7h.js";import{C as ye}from"./ComboDynamique-BzWI4ISP.js";import{u as we,b as x,s as l,S as A,j as xe}from"./index-BxIwIJfy.js";import{b as _e,B as je,g as ke}from"./primevue-CfIk0_DY.js";import{a as i,o as De,i as $e,b as p,c as k,k as b,p as m,d as a,v as r,l as G,a7 as f,t as z,j as q,T as Ce,H as he,F as Ie,E as Pe,y as V}from"./vue-core-Di3IuVqe.js";import{u as Ae}from"./usePagerDetail-BeqYPv-1.js";import{D as Ve}from"./DataGrid-CoMfrBJA.js";import{N as Fe}from"./NumeroChip-QCXXOqUM.js";import{I as Me}from"./InfoBulle-R_p1ZfIR.js";import"./ReportViewer-BNzhW7G2.js";import"./stimulsoft-B2-Y-rC1.js";import"./cjs-helpers-psZwOBky.js";import"./PDFButton-DhVJ6hNy.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const Ee={key:1,class:"omag-drawer",style:{"--omag-drawer-w":"640px"}},Te={class:"omag-drawer-header"},Se={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},Le={key:5,class:"flex items-center",style:{"margin-left":"auto",gap:"2px"}},Re={style:{"min-width":"54px","text-align":"center",color:"#6b7280"}},Be={class:"m-4 omag-form"},Ue={class:"omag-form-grid"},Ne={class:"field omag-col-full"},Ge={class:"field omag-col-full"},ze={class:"field"},qe={class:"field"},Oe={class:"field omag-col-full"},He={class:"flex items-center mb-1",style:{gap:"6px"}},We={class:"page-wrapper"},Je={class:"w-full flex flex-row items-center gap-3 p-2"},Ke={class:"grille-container"},pt={__name:"Projets",props:{ndoc:{type:String,default:""}},setup(O){const{confirmAction:H,showError:g,showInfo:F,showWarn:W}=we(),M=O,D=i(),y=i(),J=i([]),u=i({}),K=i(null),w=i([]),v=i(!1),_=i(null),c=i(!1),n=i(!1),Q=i(!1),$=i(!1),X=i(""),Y=i(""),j=i(M.ndoc||""),E=i(null),T=i(null),d=Pe({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),Z=({event:t,ndoc:e,rowIndex:s})=>{j.value=e,_.value=s,h()},ee=({selectedRows:t})=>{J.value=t,K.value=t.length>0?t[0]:null},te=t=>{y.value=t.api},le=[{label:"Ajouter",icon:"pi pi-plus-circle",command:()=>S(),disabled:V(()=>!d.ajout)},{label:"Supprimer",icon:"pi pi-trash",command:()=>pe(),disabled:V(()=>!d.supp)}],se=[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>re()},{label:"Imprimer la liste",icon:"pi pi-print",command:()=>ue()}];De(async()=>{await oe(),j.value?(h(),c.value=!0,n.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)):C()});const oe=async()=>{try{const e=(await x.post(`${l.lienApi}/verifierDroit/${l.state.dbCommun6}`,{id_utilisateur:l.userId,id_page:901,mail:l.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(d.lecture=e.lecture,d.ajout=e.ajout,d.modif=e.modif,d.supp=e.supp,d.devalidation=e.devalidation,d.validation=e.validation),d.lecture||(W("Vous n'avez pas le droit, veuillez consulter l'administrateur"),A("Projets"))}catch(t){g("Une erreur s'est produite lors de la vérification des droits."+t)}},C=async()=>{l.state.afficher_in_progress=!0;try{v.value=!1,X.value=Y.value;const t=await x.post(`${l.lienApi}/projets/${l.db}`,{},{headers:{"Content-Type":"application/json"}});w.value=t.data}catch(t){g(`Une erreur est survenue lors de l'affichage des données. ${t}`)}finally{l.state.afficher_in_progress=!1}},S=async()=>{try{const t=await x.post(`${l.lienApi}/ajouterEtRenvoyerProjet/${l.db}`);u.value=t.data,v.value=!0,c.value=!0,n.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)}catch(t){g(`Une erreur est survenue lors de l'ajout du projet. ${t}`)}finally{l.state.afficher_in_progress=!1}},ae=async()=>{c.value=!0,n.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)},ie=async()=>{try{const t=`${l.lienApi}/enregistrerProjets/${l.db}/${u.value.IdProjet}`;await x.post(t,u.value,{headers:{"Content-Type":"application/json"}}),c.value=!1,n.value=!1}catch(t){const e=t.response?.data?.message||t.message;g(`Une erreur est survenue : 
 ${e}`)}finally{l.state.afficher_in_progress=!1}},ne=()=>{c.value=!1,n.value=!1},L=async()=>{n.value&&!await H({message:"Des modifications ne sont pas enregistrées. Fermer et les perdre ?"})||(c.value=!1,n.value=!1,R())},R=()=>{M.ndoc?A("Projets"):(v.value=!1,C(),_.value!=null&&y.value&&setTimeout(()=>{const t=y.value.getDisplayedRowCount();if(t>0){const e=Math.min(_.value,t-1),s=y.value.getDisplayedRowAtIndex(e);s&&(y.value.deselectAll(),s.setSelected(!0),y.value.ensureNodeVisible(s,"middle"))}},100))},re=()=>{if(!D.value){F("Grille non initialisée");return}if(w.value.length===0){F("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");D.value.exportToExcel(`Liste des projets_${l.state.enreg_societe.Nom}_${e}.xlsx`)},ue=()=>{$.value=!0},h=async()=>{try{const t=await x.post(`${l.lienApi}/unProjet/${l.db}/${j.value}`);u.value=t.data,v.value=!0}catch(t){g(`Une erreur est survenue lors de l'affichage des détails du projet.
 ${t}`)}finally{l.state.afficher_in_progress=!1}},de=V(()=>w.value.map(t=>t.ndoc)),ce=async()=>{c.value=!1,n.value=!1,await h()},{totalListe:I,positionCourante:P,naviguer:B}=Ae({listeNdocs:de,ndoc:j,charger:ce,estEnEdition:n,onNaviguer:t=>{const e=w.value.findIndex(s=>s.ndoc===t);e!==-1&&(_.value=e)}}),pe=async()=>{try{const t=`${l.lienApi}/supprimerProjets/${l.db}/${u.value.IdProjet}`;await x.post(t),v.value=!1,c.value=!1,Q.value=!1,C()}catch(t){const e=t.response?.data?.message||t.message;g(`Une erreur est survenue :
 ${e}`)}};return(t,e)=>{const s=_e,U=je,me=ke,N=xe,fe=ye,ve=ge,be=$e("maxlen-db");return p(),k(Ie,null,[(p(),b(Ce,{to:"body"},[v.value&&d.lecture?(p(),k("div",{key:0,class:"omag-drawer-scrim",onClick:L})):m("",!0),v.value&&d.lecture?(p(),k("div",Ee,[a("div",Te,[e[14]||(e[14]=a("span",{class:"omag-drawer-title"},"Projet",-1)),r(s,{icon:"pi pi-times",text:"",rounded:"",onClick:L,title:"Fermer"})]),a("div",Se,[n.value?m("",!0):(p(),b(s,{key:0,icon:"pi pi-pencil",label:"Modifier",text:"",onClick:e[0]||(e[0]=o=>ae()),disabled:!d.modif},null,8,["disabled"])),n.value?m("",!0):(p(),b(U,{key:1,ref_key:"actionsMenu",ref:E,model:le,popup:!0},{button:G(()=>[r(s,{icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=o=>E.value.toggle(o))})]),_:1},512)),n.value?m("",!0):(p(),b(s,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:R})),n.value?(p(),b(s,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=o=>ie())})):m("",!0),n.value?(p(),b(s,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=o=>ne())})):m("",!0),!n.value&&f(I)>1?(p(),k("div",Le,[r(s,{icon:"pi pi-chevron-left",text:"",rounded:"",disabled:f(P)<=1,onClick:e[4]||(e[4]=o=>f(B)(-1)),title:"Précédent (Alt + ←)"},null,8,["disabled"]),a("span",Re,z(f(P))+" / "+z(f(I)),1),r(s,{icon:"pi pi-chevron-right",text:"",rounded:"",disabled:f(P)>=f(I),onClick:e[5]||(e[5]=o=>f(B)(1)),title:"Suivant (Alt + →)"},null,8,["disabled"])])):m("",!0)]),a("div",Be,[a("div",Ue,[a("div",Ne,[r(Fe,{value:u.value.IdProjet},null,8,["value"])]),a("div",Ge,[e[15]||(e[15]=a("label",{for:"inputFocus",class:"block mb-1"},"Libellé",-1)),q(r(me,{size:"small",id:"inputFocus",modelValue:u.value.Libelle,"onUpdate:modelValue":e[6]||(e[6]=o=>u.value.Libelle=o),class:"w-full",disabled:!c.value},null,8,["modelValue","disabled"]),[[be,"projets.Libelle"]])]),a("div",ze,[e[16]||(e[16]=a("label",{for:"dateDebut",class:"block mb-1"},"Date Début",-1)),r(N,{size:"small",id:"dateDebut",modelValue:u.value.DateDebut,"onUpdate:modelValue":e[7]||(e[7]=o=>u.value.DateDebut=o),"input-class":"w-full",disabled:!c.value},null,8,["modelValue","disabled"])]),a("div",qe,[e[17]||(e[17]=a("label",{for:"dateFin",class:"block mb-1"},"Date Fin",-1)),r(N,{size:"small",id:"dateFin",modelValue:u.value.DateFin,"onUpdate:modelValue":e[8]||(e[8]=o=>u.value.DateFin=o),"input-class":"w-full",disabled:!c.value},null,8,["modelValue","disabled"])]),a("div",Oe,[a("div",He,[e[18]||(e[18]=a("label",{for:"commercial"},"Commercial",-1)),r(Me,{text:"Commercial responsable du suivi du projet."})]),r(fe,{id:"responsable",modelValue:u.value.IDcommercial,"onUpdate:modelValue":e[9]||(e[9]=o=>u.value.IDcommercial=o),placeholder:"Responsable",table:"commercial",ajouter:!0,enabled:c.value,class:"w-full"},null,8,["modelValue","enabled"])])])])])):m("",!0)])),q(a("div",We,[a("div",Je,[r(s,{icon:"pi pi-plus-circle",label:"Ajouter",text:"",onClick:e[10]||(e[10]=o=>S()),disabled:!d.ajout},null,8,["disabled"]),r(U,{ref_key:"listeMenu",ref:T,model:se,popup:!0},{button:G(()=>[r(s,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[11]||(e[11]=o=>T.value.toggle(o))})]),_:1},512),r(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[12]||(e[12]=o=>f(A)("Projets"))})]),a("div",Ke,[r(Ve,{ref_key:"dataGrid",ref:D,"excel-file-name":"Projets","excel-sheet-name":"Projets","row-data":w.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:Z,onSelectionChanged:ee,onGridReady:te},null,8,["row-data"])])],512),[[he,d.lecture]]),$.value?(p(),b(ve,{key:0,data:w.value,showModelSelector:!0,listeModelType:"Liste des projets",modeList:!0,onClose:e[13]||(e[13]=o=>$.value=!1)},null,8,["data"])):m("",!0)],64)}}};export{pt as default};
