import{f as N,o as c,c as $,an as z,ap as L,b as o,a as g,z as G,q,i as v,d as f,M as H,F as J,r as a}from"./vendor-0kGcmQpG.js";import{_ as K}from"./DataGrid-tb6QVwpZ.js";import{u as O,s as l,a as b,S as P}from"./index-Bn9WoKhP.js";import"./useAgGridConfig-DjXMc6wb.js";const Q={class:"flex flex-col"},W={class:"flex flex-row justify-start gap-3"},X={style:{height:"calc(100vh - 150px)"}},Y={key:0},Z={class:"w-full flex flex-wrap items-start md:flex-row justify-start gap-3"},ee={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},se={class:"w-full bg-white p-3 h-[calc(100vh-140px)] overflow-auto"},te={class:"grid"},le={class:"md:w-2/3"},ae={class:"p-float-label"},ce={__name:"FamillesImmobilisations",setup(oe){const{confirmAction:k,showSuccess:F,showError:p}=O(),C=a(),m=a(),r=a({}),j=a(null),w=a([]),u=a(!1),_=a(null),d=a(!1),i=a(!1),h=a(""),A=s=>{m.value=s.api},I=({selectedRows:s})=>{j.value=s&&s.length>0?s[0]:null},E=({ndoc:s,rowIndex:e})=>{h.value=s,_.value=e,M()},x=a({ajout:!0,modif:!0});N(async()=>{await y()});const y=async()=>{l.state.afficher_in_progress=!0,u.value=!1;try{const s=await b.post(`${l.lienApi}/Famille_immo/${l.db}`,{},{headers:{"Content-Type":"application/json"}});w.value=s.data}catch(s){const e=s.response?.data?.message||s.message;p(`Une erreur est survenue : ${e}`)}finally{l.state.afficher_in_progress=!1}},M=async()=>{try{const s=await b.post(`${l.lienApi}/unFamille_immo/${l.db}/${h.value}`);r.value=s.data,u.value=!0}catch{p("Une erreur est survenue lors de l'affichage des détails")}},R=async()=>{try{const s=`${l.lienApi}/enregistrerFamille_immo/${l.db}/${r.value.IDFamille_immo}`;await b.post(s,r.value,{headers:{"Content-Type":"application/json"}}),d.value=!1,i.value=!1}catch(s){const e=s.response?.data?.message||s.message;p(`Une erreur est survenue : ${e}`)}finally{l.state.afficher_in_progress=!1}},S=()=>{d.value=!1,i.value=!1},D=()=>{u.value=!1,y(),_.value!=null&&m.value&&setTimeout(()=>{const s=m.value.getDisplayedRowCount();if(s>0){const e=Math.min(_.value,s-1),t=m.value.getDisplayedRowAtIndex(e);t&&(m.value.deselectAll(),t.setSelected(!0),m.value.ensureNodeVisible(t,"middle"))}},100)},T=async()=>{if(await k({message:"Voulez-vous vraiment supprimer cette famille d'immobilisation ?"}))try{const e=`${l.lienApi}/supprimerFamille_immo/${l.db}/${r.value.IDFamille_immo}`;await b.post(e),u.value=!1,d.value=!1,await y(),F("Famille d'immobilisation supprimée avec succès")}catch(e){const t=e.response?.data?.message||e.message;p(`Une erreur est survenue : ${t}`)}},V=async()=>{try{const s=await b.post(`${l.lienApi}/AjouterEtRenvoyerFamille_immo/${l.db}`);r.value=s.data,u.value=!0,d.value=!0,i.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)}catch{p("Une erreur est survenue lors de l'ajout")}},B=async()=>{d.value=!0,i.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)};return(s,e)=>{const t=G,U=H;return c(),$(J,null,[z(o("div",Q,[o("div",W,[g(t,{text:"",icon:"pi pi-plus-circle",label:"Ajouter",onClick:e[0]||(e[0]=n=>V()),disabled:!x.value?.ajout},null,8,["disabled"]),g(t,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=n=>q(P)("FamillesImmobilisations"))})]),o("div",X,[g(K,{ref_key:"gridListe",ref:C,"excel-file-name":"Familles immobilisations","excel-sheet-name":"Familles immobilisations","row-data":w.value,"document-number-fields":["ndoc"],"column-widths":{libelle:400},"enable-totals":!1,"show-checkbox":!1,onGridReady:A,onSelectionChanged:I,onRowClicked:E},null,8,["row-data"])])],512),[[L,!u.value]]),u.value?(c(),$("div",Y,[o("div",Z,[i.value?f("",!0):(c(),v(t,{key:0,onClick:e[2]||(e[2]=n=>B()),text:"",icon:"pi pi-pencil",label:"Modifier",disabled:!x.value?.modif},null,8,["disabled"])),i.value?f("",!0):(c(),v(t,{key:1,text:"",icon:"pi pi-trash",label:"Supprimer",onClick:e[3]||(e[3]=n=>T())})),i.value?f("",!0):(c(),v(t,{key:2,text:"",icon:"pi pi-arrow-left",label:"Retour",onClick:e[4]||(e[4]=n=>D())}))]),o("div",ee,[i.value?(c(),v(t,{key:0,text:"",icon:"pi pi-save",label:"Enregistrer",onClick:e[5]||(e[5]=n=>R())})):f("",!0),i.value?(c(),v(t,{key:1,text:"",icon:"pi pi-times",label:"Annuler",onClick:e[6]||(e[6]=n=>S())})):f("",!0)]),o("div",se,[o("div",te,[o("div",le,[o("span",ae,[e[8]||(e[8]=o("label",{for:"inputFocus"},"Familles immobilisations",-1)),g(U,{size:"small",id:"inputFocus",modelValue:r.value.libelle_fam_immo,"onUpdate:modelValue":e[7]||(e[7]=n=>r.value.libelle_fam_immo=n),disabled:!d.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])])):f("",!0)],64)}}};export{ce as default};
