import{_ as Q}from"./FavorisSwitch-DD6nTfzi.js";import{r,f as X,o as d,c as C,b as l,i as _,z as Y,d as m,a as c,av as Z,M as ee,an as te,ap as se,q as ae,F as oe,ar as le}from"./vendor-0kGcmQpG.js";import{u as ie,a as b,s,S as A}from"./index-Bn9WoKhP.js";import{_ as ne}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const re={key:0},ue={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},ce={class:"justify-self-end ml-auto mr-3 font-bold text-xl"},de={class:"w-full bg-white p-3"},pe={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"},fe={class:"field"},me={class:"field"},ve={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},ge={class:"flex flex-col gap-2 sm:flex-row sm:gap-3"},be={class:"flex flex-wrap gap-2 sm:gap-3"},_e={class:"flex items-center gap-3"},we={style:{height:"calc(100vh - 250px)",width:"100%"}},xe={key:1,class:"p-4 text-red-600 font-semibold text-center"},Ce={__name:"StatutContrat",props:["ndoc"],setup(T){const{confirmAction:D,showSuccess:j,showError:v,showInfo:w,showWarn:M}=ie(),x=T,y=r(x.ndoc),n=r({}),h=r([]),p=r(!1),$=r(null),f=r(!1),u=r(!1),R=r(!1),k=r(),g=r(),F=r([]),z=({event:t,ndoc:e,rowIndex:a})=>{t?.target?.closest(".ag-selection-checkbox, .ag-checkbox, input")||(window.getSelection&&window.getSelection().removeAllRanges(),y.value=e,$.value=a,I())},B=({selectedRows:t})=>{F.value=t},U=t=>{g.value=t.api},o=le({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1});X(async()=>{await N(),x.ndoc?(I(),f.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):S()});const N=async()=>{try{const e=(await b.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:307,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(o.lecture=e.lecture,o.ajout=e.ajout,o.modif=e.modif,o.supp=e.supp,o.devalidation=e.devalidation,o.validation=e.validation),o.lecture||(M("Vous n'avez pas le droit, veuillez consulter l'administrateur"),A("StatutContrat"))}catch(t){v(`Une erreur s'est produite lors de la vérification des droits. ${t}`)}},S=async()=>{s.state.afficher_in_progress=!0;try{p.value=!1;const t=await b.post(`${s.lienApi}/statut_contrats/${s.db}`,{});h.value=t.data.map(e=>({...e,ndoc:e.statut_id}))}catch(t){v(`Une erreur est survenue lors de l'affichage des statuts de contrat ${t}`)}finally{s.state.afficher_in_progress=!1}},V=async()=>{try{const t=await b.post(`${s.lienApi}/AjouterEtRenvoyerstatut_contrat/${s.db}`);n.value=t.data,y.value=n.value.statut_id,p.value=!0,f.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(t){v(`Une erreur est survenue lors de l'ajout d'un statut de contrat
 ${t}`)}},G=async()=>{try{if(!n.value.Libelle){M("Le libellé est obligatoire");return}const t=`${s.lienApi}/enregistrerStatut_contrat/${s.db}/${n.value.statut_id}`;await b.post(t,n.value,{headers:{"Content-Type":"application/json"}}),f.value=!1,u.value=!1,j("Les modifications ont été enregistrées avec succès")}catch(t){const e=t.response?.data?.message||t.message;v("Une erreur est survenue : "+e)}finally{s.state.afficher_in_progress=!1}},O=()=>{f.value=!1,u.value=!1},q=()=>{if(!k.value){w("Grille non initialisée");return}if(h.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");k.value.exportToExcel(`Liste des statuts de contrat_${s.state.enreg_societe.Nom}_${e}.xlsx`)},W=()=>{w("Impression de la liste en cours...")},I=async()=>{try{const t=await b.post(`${s.lienApi}/unstatut_contrat/${s.db}/${y.value}`);n.value=t.data,p.value=!0}catch(t){v(`Une erreur est survenue lors de l'affichage des détails du statut de contrat ${t}`)}},H=async()=>{f.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},J=async()=>{if(await D({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${s.lienApi}/supprimerStatut_contrat/${s.db}/${n.value.statut_id}`;await b.post(e),p.value=!1,f.value=!1,S(),j("Suppression effectuée avec succès")}catch(e){const a=e.response?.data?.message||e.message;v("Une erreur est survenue : "+a)}},K=()=>{x.ndoc?A("StatutContrat"):(p.value=!1,S(),$.value!=null&&g.value&&setTimeout(()=>{const t=g.value.getDisplayedRowCount();if(t>0){const e=Math.min($.value,t-1),a=g.value.getDisplayedRowAtIndex(e);a&&(g.value.deselectAll(),a.setSelected(!0),g.value.ensureNodeVisible(a,"middle"))}},100))};return(t,e)=>{const a=Y,L=Z,E=ee,P=Q;return d(),C(oe,null,[p.value&&o.lecture?(d(),C("div",re,[l("div",ue,[u.value?m("",!0):(d(),_(a,{key:0,onClick:e[0]||(e[0]=i=>H()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!o.modif},null,8,["disabled"])),u.value?m("",!0):(d(),_(a,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=i=>t.$refs.actionsMenu.toggle(i)),text:""})),c(L,{ref:"actionsMenu",model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:V,disabled:!o.ajout},{label:"Supprimer",icon:"pi pi-trash",command:J,disabled:!o.supp,class:"text-red-500"}],popup:!0},null,8,["model"]),u.value?m("",!0):(d(),_(a,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:K})),u.value?(d(),_(a,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=i=>G())})):m("",!0),u.value?(d(),_(a,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=i=>O())})):m("",!0),l("div",ce,[c(a,{icon:"pi pi-paperclip",text:"",class:"p-button-rounded",onClick:e[4]||(e[4]=i=>R.value=!R.value)})])]),l("div",de,[l("div",pe,[l("div",fe,[e[9]||(e[9]=l("label",{for:"statut_id",class:"block mb-1"},"Numéro",-1)),c(E,{size:"small",id:"statut_id",modelValue:n.value.statut_id,"onUpdate:modelValue":e[5]||(e[5]=i=>n.value.statut_id=i),class:"w-full",disabled:""},null,8,["modelValue"])]),l("div",me,[e[10]||(e[10]=l("label",{for:"inputFocus",class:"block mb-1"},"Libellé",-1)),c(E,{size:"small",id:"inputFocus",modelValue:n.value.Libelle,"onUpdate:modelValue":e[6]||(e[6]=i=>n.value.Libelle=i),disabled:!f.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])):m("",!0),te(l("div",null,[l("div",ve,[l("div",ge,[l("div",be,[c(a,{icon:"pi pi-plus",label:"Ajouter",onClick:V,text:"",disabled:!o.ajout},null,8,["disabled"]),c(a,{label:"Actions",icon:"pi pi-cog",onClick:e[7]||(e[7]=i=>t.$refs.actionsMenuList.toggle(i)),text:""}),c(L,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:q},{label:"Imprimer la liste",icon:"pi pi-print",command:W}],popup:!0},null,8,["model"]),c(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[8]||(e[8]=i=>ae(A)("StatutContrat"))})])]),l("div",_e,[c(P,{fen:"StatutContrat",text:"Statut contrat"})])]),l("div",we,[c(ne,{ref_key:"dataGrid",ref:k,"excel-file-name":"Statut contrat","excel-sheet-name":"Statut contrat","row-data":h.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{statut_id:100,Libelle:300},"enable-totals":!1,onRowClicked:z,onSelectionChanged:B,onGridReady:U},null,8,["row-data"])])],512),[[se,!p.value&&o.lecture]]),o.lecture?m("",!0):(d(),C("div",xe," Vous n'avez pas le droit, veuillez consulter l'administrateur "))],64)}}};export{Ce as default};
