import{f as j,w as B,o as D,c as I,b as p,a as s,z as R,av as W,q as z,ax as P,r as n,e as c}from"./vendor-0kGcmQpG.js";import{u as U,s as l,a as H,S as K}from"./index-Bn9WoKhP.js";import{_ as Q}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const X={class:"w-full flex flex-col overflow-hidden overflow-y-auto gap-2",style:{height:"calc(100vh - 108px)"}},Y={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},Z={class:"btns flex items-center gap-2"},ee={class:"lg:ml-4"},te={style:{height:"calc(100vh - 200px)"}},re={__name:"statisitiqueCompta",setup(oe){const{showError:S,showInfo:g}=U(),d=n([]),b=n(),v=n(),M=n(),o=n("ecritures"),w=[{name:"Écritures",value:"ecritures"},{name:"Journaux",value:"journaux"},{name:"Trésorerie (Solde)",value:"tresorerie"},{name:"Classe 6",value:"classe6"},{name:"Classe 7",value:"classe7"}],r=["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"],A=c(()=>o.value!=="ecritures"),y=c(()=>o.value==="tresorerie"?[...r]:[...r,"Total"]),C=c(()=>o.value==="tresorerie"?["Libelle",...r,"Graphe"]:["Libelle",...r,"Total","Graphe"]),G=n({Libelle:280,Janvier:85,Février:85,Mars:85,Avril:85,Mai:85,Juin:85,Juillet:85,Août:85,Septembre:85,Octobre:85,Novembre:85,Décembre:85,Total:100,Graphe:{flex:1,minWidth:150}}),$=c(()=>`Statistique_${w.find(e=>e.value===o.value)?.name||"Statistique"}`),T=c(()=>[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>N()}]),q=t=>{if(!t.data)return"";const e=r.map(_=>parseFloat(t.data[_])||0),i=Math.max(...e),u=Math.min(...e),h=i-u||1,a=(t.column?.getActualWidth()||200)-20,x=28,m=2,V=e.map((_,F)=>{const L=m+F*(a-2*m)/11,O=x-m-(_-u)/h*(x-2*m);return`${L},${O}`}).join(" "),k=e[e.length-1]-e[0],E=k>0?"#22c55e":k<0?"#ef4444":"#6b7280";return`<svg width="${a}" height="${x}" style="display:block;">
    <polyline points="${V}" fill="none" stroke="${E}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`},J=t=>{M.value=t.api};j(()=>{f()}),B(o,()=>{f()});const f=async()=>{l.state.afficher_in_progress=!0;try{const{data:t}=await H.post(`${l.lienApi}/SP_StatistiqueCompta/${l.db}`,{annee_fiscale:l.state.annee_fiscale,type:o.value},{headers:{"Content-Type":"application/json"}});d.value=t.map(e=>({...e,Graphe:""}))}catch(t){S(`${t.message}`)}finally{l.state.afficher_in_progress=!1}},N=()=>{if(!v.value){g("Grille non initialisée");return}if(d.value.length===0){g("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");v.value.exportToExcel(`Statistique_${o.value}_${l.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const i=R,u=W,h=P;return D(),I("div",X,[p("div",Y,[p("div",Z,[s(i,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=a=>f())}),s(u,{ref_key:"actionsMenu",ref:b,popup:!0,model:T.value},null,8,["model"]),s(i,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=a=>b.value.toggle(a))}),s(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=a=>z(K)("statisitiqueCompta"))})]),p("div",ee,[s(h,{size:"small",modelValue:o.value,"onUpdate:modelValue":e[3]||(e[3]=a=>o.value=a),options:w,optionLabel:"name",optionValue:"value",class:"w-64"},null,8,["modelValue"])])]),p("div",te,[s(Q,{ref_key:"dataGrid",ref:v,"excel-file-name":$.value,"excel-sheet-name":$.value,"row-data":d.value,"numeric-columns":y.value,"column-widths":G.value,"column-order":C.value,"enable-totals":A.value,"totals-columns":y.value,"custom-renderers":{Graphe:q},onGridReady:J},null,8,["excel-file-name","excel-sheet-name","row-data","numeric-columns","column-widths","column-order","enable-totals","totals-columns","custom-renderers"])])])}}};export{re as default};
