import"./index-BSaHX2oa.js";import{r as x}from"./vendor-BDR7yMJi.js";function I(){const m=["montant","prix","total","tva","ttc","ht","qte","quantite","solde","mt","remise","entree","sortie","debit","credit"],C=["date","created","updated","date_ech","dateech"],p=(t,a)=>a.some(o=>t.includes(o)),h=t=>p(t.toLowerCase(),m),b=t=>p(t.toLowerCase(),C),S=x({sortable:!0,filter:"agTextColumnFilter",floatingFilter:!1,resizable:!0,suppressHeaderMenuButton:!0}),y=x({mode:"multiRow",checkboxes:!0,headerCheckbox:!0,enableClickSelection:!1}),g=(t,a,o=[],c={})=>{if(!t?.value?.api||!a?.value||a.value.length===0)return[];let d=0;const r={},s=[],f=a.value[0],v=[],i={};Object.keys(f).forEach(e=>{if(o.length>0?o.includes(e):h(e)){s.push(e);const l=c[e]||"sum";l==="sum"||l==="avg"?r[e]={type:l,value:0,count:0}:l==="min"?r[e]={type:l,value:1/0}:l==="max"?r[e]={type:l,value:-1/0}:r[e]={type:l,values:[]},i[e]=0}else i[e]=""}),t.value.api.forEachNodeAfterFilter(e=>{e.data&&(d++,v.push(e.data),s.forEach(n=>{const l=parseFloat(e.data[n])||0,u=r[n];switch(u.type){case"sum":u.value+=l;break;case"avg":u.value+=l,u.count++;break;case"min":u.value=Math.min(u.value,l);break;case"max":u.value=Math.max(u.value,l);break;case"first":case"last":u.values.push(l);break}}))});const w=Object.keys(f)[0];return i[w]=`${d} lignes`,Object.keys(r).forEach(e=>{const n=r[e];switch(n.type){case"sum":i[e]=n.value;break;case"avg":i[e]=n.count>0?n.value/n.count:0;break;case"min":case"max":i[e]=n.value!==1/0&&n.value!==-1/0?n.value:0;break;case"first":i[e]=n.values.length>0?n.values[0]:0;break;case"last":i[e]=n.values.length>0?n.values[n.values.length-1]:0;break}}),[i]};return{isNumericColumn:h,isDateColumn:b,defaultColDef:S,rowSelection:y,textValueSetter:t=>{const a=t.colDef.field,o=t.newValue??"";return t.data[a]!==o?(t.data[a]=o,!0):!1},numericValueSetter:t=>{const a=t.colDef.field,o=t.newValue??0,c=typeof o=="number"?o:parseFloat(o)||0;return t.data[a]!==c?(t.data[a]=c,!0):!1},createValueSetter:(t="")=>a=>{const o=a.colDef.field,c=a.newValue??t;return a.data[o]!==c?(a.data[o]=c,!0):!1},calculerTotaux:g,getContextMenuItems:(t,a,o,c,d=[],r={})=>{if(!t||!t.column||!t.column.getColDef)return["copy","copyWithHeaders","separator","export"];const s=t.column.getColDef().field;return s?(d.length>0?d.includes(s):h(s))?["copy","copyWithHeaders","separator",{name:"Afficher les totaux",icon:'<i class="pi pi-calculator"></i>',action:()=>{a.value=g(o,c,d,r)}},{name:"Masquer les totaux",icon:'<i class="pi pi-times"></i>',action:()=>{a.value=[]}},"separator","export"]:["copy","copyWithHeaders","separator","export"]:["copy","copyWithHeaders","separator","export"]},createGridEventHandlers:(t,a,o,c,d=[],r={},s=[])=>({onGridReady:e=>{t.value=e.api},onSelectionChanged:e=>e.api.getSelectedRows(),onFilterChanged:()=>{c?.value?.api&&a?.value&&a.value.length>0&&o?.value?.length>0&&setTimeout(()=>{o.value=g(c,a,d,r)},0)},onRowClick:(e,n)=>{if(e.event.target.closest(".ag-selection-checkbox, .ag-checkbox, input"))return;window.getSelection&&window.getSelection().removeAllRanges();let l=null;if(s&&s.length>0){for(const u of s)if(e.data&&u in e.data&&e.data[u]!==null&&e.data[u]!==void 0){l=e.data[u];break}}else e.data&&"ndoc"in e.data&&e.data.ndoc!==null&&e.data.ndoc!==void 0&&(l=e.data.ndoc);l!=null&&n&&n(l)}})}}export{I as u};
