import{r as l,f as X,o as f,c as E,b as o,i as w,z as Y,d as g,a as c,av as Z,M as ee,an as te,ap as ie,q as ae,F as se,ar as le}from"./vendor-BDR7yMJi.js";import{u as oe,a as b,s as i,S as C}from"./index-BSaHX2oa.js";import{_ as ne}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.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"},we={style:{height:"calc(100vh - 250px)",width:"100%"}},$e={__name:"Qualification",props:["ndoc"],setup(N){const{confirmAction:T,showSuccess:D,showError:m,showInfo:x,showWarn:Q}=oe(),y=N,_=l(y.ndoc),r=l({}),h=l([]),d=l(!1),$=l(null),p=l(!1),u=l(!1),k=l(),v=l(),q=l([]),B=({event:t,ndoc:e,rowIndex:a})=>{t?.target?.closest(".ag-selection-checkbox, .ag-checkbox, input")||(window.getSelection&&window.getSelection().removeAllRanges(),_.value=e,$.value=a,R())},F=({selectedRows:t})=>{q.value=t},U=t=>{v.value=t.api},j=l(""),L=l(""),S=l(!1),s=le({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1});X(async()=>{await z(),y.ndoc?(R(),p.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):A()});const z=async()=>{try{const e=(await b.post(`${i.lienApi}/verifierDroit/${i.state.dbCommun6}`,{id_utilisateur:i.userId,id_page:1410,mail:i.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(s.lecture=e.lecture,s.ajout=e.ajout,s.modif=e.modif,s.supp=e.supp,s.devalidation=e.devalidation,s.validation=e.validation),s.lecture||(Q("Vous n'avez pas le droit, veuillez consulter l'administrateur"),C("Qualification"))}catch(t){m(`Une erreur s'est produite lors de la vérification des droits. ${t}`)}},A=async()=>{i.state.afficher_in_progress=!0;try{d.value=!1,j.value=L.value;const t=await b.post(`${i.lienApi}/qualifications/${i.db}`,{condition:j.value});h.value=t.data.map(e=>({...e,ndoc:e.id_Qualification}))}catch(t){m(`Une erreur est survenue lors de l'affichage des qualifications ${t}`)}finally{i.state.afficher_in_progress=!1}},M=async()=>{try{const t=await b.post(`${i.lienApi}/AjouterEtRenvoyerQualification/${i.db}`);r.value=t.data,_.value=r.value.id_Qualification,d.value=!0,p.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(t){m(`Une erreur est survenue lors de l'ajout d'une qualification
 ${t}`)}},G=async()=>{try{if(!r.value.Nom){Q("Le libellé est obligatoire");return}const t=`${i.lienApi}/enregistrerQualification/${i.db}/${r.value.id_Qualification}`;await b.post(t,r.value,{headers:{"Content-Type":"application/json"}}),p.value=!1,u.value=!1}catch(t){const e=t.response?.data?.message||t.message;m("Une erreur est survenue : "+e)}finally{i.state.afficher_in_progress=!1}},O=()=>{p.value=!1,u.value=!1},P=()=>{if(!k.value){x("Grille non initialisée");return}if(h.value.length===0){x("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");k.value.exportToExcel(`Liste des qualifications_${i.state.enreg_societe.Nom}_${e}.xlsx`)},W=()=>{x("Impression de la liste en cours...")},R=async()=>{try{const t=await b.post(`${i.lienApi}/unQualification/${i.db}/${_.value}`);r.value=t.data,d.value=!0}catch(t){m(`Une erreur est survenue lors de l'affichage des détails de la qualification ${t}`)}},H=async()=>{p.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},J=async()=>{if(await T({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${i.lienApi}/supprimerQualification/${i.db}/${r.value.id_Qualification}`;await b.post(e),d.value=!1,p.value=!1,A(),D("Suppression effectuée avec succès")}catch(e){const a=e.response?.data?.message||e.message;m("Une erreur est survenue : "+a)}},K=()=>{y.ndoc?C("Qualification"):(d.value=!1,A(),$.value!=null&&v.value&&setTimeout(()=>{const t=v.value.getDisplayedRowCount();if(t>0){const e=Math.min($.value,t-1),a=v.value.getDisplayedRowAtIndex(e);a&&(v.value.deselectAll(),a.setSelected(!0),v.value.ensureNodeVisible(a,"middle"))}},100))};return(t,e)=>{const a=Y,I=Z,V=ee;return f(),E(se,null,[d.value&&s.lecture?(f(),E("div",re,[o("div",ue,[u.value?g("",!0):(f(),w(a,{key:0,onClick:e[0]||(e[0]=n=>H()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!s.modif},null,8,["disabled"])),u.value?g("",!0):(f(),w(a,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=n=>t.$refs.actionsMenu.toggle(n)),text:""})),c(I,{ref:"actionsMenu",model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:M,disabled:!s.ajout},{label:"Supprimer",icon:"pi pi-trash",command:J,disabled:!s.supp,class:"text-red-500"}],popup:!0},null,8,["model"]),u.value?g("",!0):(f(),w(a,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:K})),u.value?(f(),w(a,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=n=>G())})):g("",!0),u.value?(f(),w(a,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=n=>O())})):g("",!0),o("div",ce,[c(a,{icon:"pi pi-paperclip",text:"",class:"p-button-rounded",onClick:e[4]||(e[4]=n=>S.value=!S.value)})])]),o("div",de,[o("div",pe,[o("div",fe,[e[9]||(e[9]=o("label",{for:"id_qualification",class:"block mb-1"},"Numéro",-1)),c(V,{size:"small",id:"id_qualification",modelValue:r.value.id_Qualification,"onUpdate:modelValue":e[5]||(e[5]=n=>r.value.id_Qualification=n),class:"w-full",disabled:""},null,8,["modelValue"])]),o("div",me,[e[10]||(e[10]=o("label",{for:"inputFocus",class:"block mb-1"},"Libellé",-1)),c(V,{size:"small",id:"inputFocus",modelValue:r.value.Nom,"onUpdate:modelValue":e[6]||(e[6]=n=>r.value.Nom=n),disabled:!p.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])):g("",!0),te(o("div",null,[o("div",ve,[o("div",ge,[o("div",be,[c(a,{icon:"pi pi-plus",label:"Ajouter",onClick:M,text:"",disabled:!s.ajout},null,8,["disabled"]),c(a,{label:"Actions",icon:"pi pi-cog",onClick:e[7]||(e[7]=n=>t.$refs.actionsMenuList.toggle(n)),text:""}),c(I,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:P},{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]=n=>ae(C)("Qualification"))})])])]),o("div",we,[c(ne,{ref_key:"dataGrid",ref:k,"excel-file-name":"Qualification","excel-sheet-name":"Qualification","row-data":h.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{id_Qualification:120,Nom:200},"enable-totals":!0,"show-checkbox":!1,onRowClicked:B,onSelectionChanged:F,onGridReady:U},null,8,["row-data"])])],512),[[ie,!d.value&&s.lecture]])],64)}}};export{$e as default};
