import{f as E,g as S,o as I,c as N,b as V,a as i,z as k,q as z,r as t}from"./vendor-0kGcmQpG.js";import{u as A,s as r,a as f,S as G,j as L}from"./index-Bn9WoKhP.js";const M={class:"w-full flex flex-row items-center gap-3 mb-4"},U={__name:"JoursFeries",setup(R){const{showError:u,confirmAction:b,showWarn:g}=A(),o=t({}),l=t(null),c=t(),d=t([]),C=t(!1),n=t(""),D=t(""),h=t(""),w=t([{field:"ID",headerName:"Code",width:80,sortable:!0,filter:"agTextColumnFilter",editable:!1},{field:"Date",headerName:"Date",width:120,sortable:!0,filter:"agTextColumnFilter",editable:!0,valueFormatter:a=>L(a.value),cellEditor:"agDateCellEditor",cellEditorParams:{format:"dd/mm"}},{field:"libelle",headerName:"Libellé",sortable:!0,filter:"agTextColumnFilter",editable:!0,width:200}]),y=t({sortable:!0,filter:"agTextColumnFilter",resizable:!0,suppressHeaderMenuButton:!0}),$=a=>{a.api.sizeColumnsToFit()},x=()=>{const a=c.value.api.getSelectedNodes();a.length>0&&(l.value=a[0].data,o.value=a[0].data,n.value=a[0].data.ID)},j=a=>{const{data:e,newValue:s,column:m}=a;e[m.colId]=s,l.value&&l.value.ID===e.ID&&(o.value={...e},n.value=e.ID)};E(async()=>{await p()});const p=async()=>{r.state.afficher_in_progress=!0;try{C.value=!1,D.value=h.value;const a=await f.post(`${r.lienApi}/jrFeries/${r.db}`,{condition:h.value},{headers:{"Content-Type":"application/json"}});d.value=a.data}catch{u("Une erreur s'est produite lors de l'affichage des jours fériés.")}finally{r.state.afficher_in_progress=!1}},F=async()=>{try{const a=await f.post(`${r.lienApi}/AjouterEtRenvoyerjrFerie/${r.db}`);o.value=a.data,d.value=[...d.value,o.value],setTimeout(()=>{l.value=o.value,n.value=o.value.ID,c.value.api.forEachNode(e=>{e.data.ID===o.value.ID&&(e.setSelected(!0),c.value.api.ensureNodeVisible(e))})},200)}catch{u("Une erreur s'est produite lors de l'ajout d'une ligne.")}},T=async()=>{if(!l.value){g("Veuillez sélectionner une ligne à enregistrer.");return}try{const a={Date:l.value.Date,libelle:l.value.libelle},e=`${r.lienApi}/enregistrerJrFerie/${r.db}/${n.value}`;await f.post(e,a,{headers:{"Content-Type":"application/json"}}),await p()}catch(a){const e=a.response?.data?.message||a.message;u(`Une erreur est survenue : ${e}`)}finally{r.state.afficher_in_progress=!1}},_=async()=>{if(!l.value){g("Veuillez sélectionner une ligne à supprimer.");return}if(await b({message:"Voulez-vous vraiment supprimer?"}))try{const e=`${r.lienApi}/supprimerJrFerie/${r.db}/${n.value}`;await f.post(e),await p()}catch(e){const s=e.response?.data?.message||e.message;u(`Une erreur est survenue :  ${s}`)}};return(a,e)=>{const s=k,m=S("ag-grid-vue");return I(),N("div",null,[V("div",M,[i(s,{icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[0]||(e[0]=v=>T())}),i(s,{icon:"pi pi-plus-circle",label:"Ajouter ligne",text:"",onClick:e[1]||(e[1]=v=>F())}),i(s,{icon:"pi pi-trash",label:"Supprimer",text:"",onClick:e[2]||(e[2]=v=>_())}),i(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[3]||(e[3]=v=>z(G)("JoursFeries"))})]),i(m,{ref_key:"agGrid",ref:c,rowData:d.value,columnDefs:w.value,defaultColDef:y.value,theme:a.$agGridTheme,localeText:a.$agGridLocale,animateRows:!0,enableRangeSelection:!0,enableCellTextSelection:!0,suppressMenuHide:!1,domLayout:"normal",rowSelection:"single",onSelectionChanged:x,onGridReady:$,onCellValueChanged:j,class:"ag-theme-quartz",style:{height:"calc(100vh - 300px)",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","theme","localeText"])])}}};export{U as default};
