import{f as _,af as D,g as $,o as k,c as y,b as c,a as u,z as S,q as Y,F as E,$ as m,r as l}from"./vendor-0kGcmQpG.js";import{u as z,S as A,a as f,s as t}from"./index-Bn9WoKhP.js";const G={class:"flex flex-row justify-start gap-2 p-1"},T={style:"height: calc(100vh - 240px)",class:"ag-theme-quartz"},F={__name:"ClotureMensuelle",setup(j){const{showError:d,showSuccess:g}=z(),r=l([]),h=l(),n=l(),p=["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],v=l([{headerName:"Mois",field:"libelleMois",flex:2,sortable:!1,filter:!1},{headerName:"Clôture",field:"Cloture",flex:1,cellRenderer:e=>e.node.rowPinned?"":`
        <div class="flex justify-center items-center h-full">
          <input type="checkbox" ${e.value?"checked":""}
                 data-mois="${e.data.mois}"
                 class="cloture-checkbox cursor-pointer"
                 style="width: 16px; height: 16px;"
                 onchange="window.handleClotureMensuelleChange && window.handleClotureMensuelleChange(this, '${e.data.mois}')" />
        </div>
      `,cellStyle:{textAlign:"center"},sortable:!1,resizable:!1,filter:!1}]),C=l({sortable:!1,resizable:!0,suppressHeaderMenuButton:!0}),b=l({mode:"singleRow",checkboxes:!1,enableClickSelection:!1}),x=e=>{n.value=e.api,window.handleClotureMensuelleChange=(s,o)=>{const a=r.value.find(i=>i.mois===o);a&&(a.Cloture=s.checked)},setTimeout(()=>{n.value&&n.value.sizeColumnsToFit()},100)},w=async()=>{try{const{data:e}=await f.post(`${t.lienApi}/getClotureMensuelle/${t.db}`,{annee_fiscale:t.state.annee_fiscale,ExerciceDu:m(t.state.enreg_option_compta.ExerciceDu).format("YYYY-MM-DD"),ExerciceAu:m(t.state.enreg_option_compta.ExerciceAu).format("YYYY-MM-DD")});r.value=e.map(s=>{const o=parseInt(s.mois.substring(4,6),10),a=s.mois.substring(0,4);return{...s,Cloture:!!s.Cloture,libelleMois:`${p[o-1]} ${a}`}})}catch(e){const s=e.response?.data?.message||e.message;d(`Une erreur est survenue : ${s}`)}},M=async()=>{try{await f.post(`${t.lienApi}/enregistrerClotureMensuelle/${t.db}`,{lignes:r.value}),g("Clôtures mensuelles enregistrées avec succès")}catch(e){const s=e.response?.data?.message||e.message;d(`Une erreur est survenue : ${s}`)}};return _(()=>{w()}),D(()=>{delete window.handleClotureMensuelleChange}),(e,s)=>{const o=S,a=$("ag-grid-vue");return k(),y(E,null,[c("div",G,[u(o,{icon:"pi pi-save",label:"Enregistrer",text:"",class:"text-blue-900",onClick:s[0]||(s[0]=i=>M())}),u(o,{icon:"pi pi-times",label:"Fermer",text:"",onClick:s[1]||(s[1]=i=>Y(A)("ClotureMensuelle"))})]),c("div",null,[c("div",T,[u(a,{ref_key:"agGrid",ref:h,localeText:e.$agGridLocale,rowData:r.value,columnDefs:v.value,defaultColDef:C.value,theme:e.$agGridTheme,rowSelection:b.value,onGridReady:x,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","rowSelection"])])])],64)}}};export{F as default};
