import{$ as ge,y as c,w as Z,h as me,b as x,c as R,v as ye,a7 as J,d as f,F as W,C as _,G as j,p as Q,q as pe,t as X,a as z}from"./vue-core-Di3IuVqe.js";import{p as he,o as we,_ as ve,t as Ce,q as be}from"./index-BxIwIJfy.js";import{u as xe}from"./useAgGridConfig-Dp3DkgaV.js";function Re(){const d=t=>({Brouillon:{bg:"#6c757d",text:"#ffffff"},"En Cours":{bg:"#17a2b8",text:"#ffffff"},Accepté:{bg:"#28a745",text:"#ffffff"},"A réviser":{bg:"#ffc107",text:"#000000"},Perdus:{bg:"#dc3545",text:"#ffffff"},Archivé:{bg:"#6f42c1",text:"#ffffff"},"Non facturé":{bg:"#fd7e14",text:"#ffffff"},Facturé:{bg:"#28a745",text:"#ffffff"},"Non Facturés Non réglé":{bg:"#dc3545",text:"#ffffff"},"Non facturés, réglé":{bg:"#17a2b8",text:"#ffffff"},"En attente":{bg:"#ffc107",text:"#000000"},Payée:{bg:"#28a745",text:"#ffffff"},Échue:{bg:"#dc3545",text:"#ffffff"},"Partiellement payée":{bg:"#007bff",text:"#ffffff"}})[t]||{bg:"#64748b",text:"#ffffff"},T=(t=null)=>{const r=t||d;return i=>{if(!i.value)return"";if(i.node.rowPinned)return`<span style="font-weight: 600;">${i.value}</span>`;const g=r(i.value);return`<span style="
        background-color: ${g.bg};
        color: ${g.text};
        padding: 0.25rem 0.75rem;
        border-radius: 0.375rem;
        font-size: 0.75rem;
        font-weight: 600;
        white-space: nowrap;
      ">${i.value}</span>`}},I=()=>t=>{if(!t.value)return"";if(t.node.rowPinned)return`<span style="font-weight: 600;">${t.value}</span>`;const r=String(t.value).toLowerCase().trim();return r==="oui"||r==="yes"||r==="1"||r==="true"||r==="validé"?`
          <div style="display: flex; align-items: center; justify-content: center; height: 100%;">
            <i class="pi pi-check-circle" style="color: #22c55e; font-size: 1.2em;" title="Validé"></i>
          </div>
        `:r==="non"||r==="no"||r==="0"||r==="false"||r==="non validé"?`
          <div style="display: flex; align-items: center; justify-content: center; height: 100%;">
            <i class="pi pi-times-circle" style="color: #ef4444; font-size: 1.2em;" title="Non validé"></i>
          </div>
        `:`<span>${t.value}</span>`},e=()=>t=>t.value?`<span class="font-mono text-blue-600 font-semibold">${t.value}</span>`:"",N=(t,r="ndoc",i="/images/profile.png",g={})=>{const S=g.size||24,w=g.rounded!==!1,A=w?"50%":"4px",v=w?"cover":"contain",O=w?"":"background:#fff; border:1px solid #eee;";return u=>{if(!u.value)return"";const F=u.data[r]||u.data.code_client||u.data.code_frs||u.data.code;let C=i;return(u.data["Code article"]||u.data.code_art||u.data.code_article)&&(C="/images/article.png"),`
        <div style="display: flex; align-items: center; gap: 8px;">
          <img src="${(t?.value?t.value[F]:t?.[F])||C}"
               style="width: ${S}px; height: ${S}px; border-radius: ${A}; object-fit: ${v}; ${O} flex-shrink: 0;"
               onerror="this.src='${C}'" />
          <span>${u.value}</span>
        </div>
      `}};return{createStatusRenderer:T,createValidationRenderer:I,createDocumentNumberRenderer:e,createEntityRenderer:N,createNumericRenderer:()=>t=>{if(t.value===null||t.value===void 0||t.value===""||t.value==="null")return"";const r=parseFloat(t.value);return isNaN(r)?"":we(r)},createDateRenderer:()=>t=>he(t.value),applyRenderers:(t,r,i={})=>{const{clientImages:g,customStatusColors:S,documentNumberFields:w=["N°Devis","Numéro","Numéro Facture"],entityNameFields:A=["Nom du client"],validationFields:v=["Validé","valide","Valid"],statusField:O="statut",imageKeyField:u="ndoc",entityImageSize:F=24,entityImageRounded:C=!0}=i;if(r===O){t.cellRenderer=T(S),t.width=t.width||170;return}if(w.includes(r)){t.cellRenderer=e(),t.width=t.width||130;return}if(A.includes(r)){t.cellRenderer=N(g,u,"/images/profile.png",{size:F,rounded:C}),t.width||(t.flex=t.flex||2,t.minWidth=t.minWidth||200);return}if(v.includes(r)||v.includes(t.headerName)){t.cellRenderer=I(),t.width=t.width||80,t.headerName="Validé";return}},getDefaultStatusColors:d}}const Se={key:0,class:"dg-skeleton-overlay","aria-label":"Chargement…"},Fe={class:"dg-skeleton-header"},De={key:1,class:"dg-empty-state"},Ne={class:"dg-empty-content"},Ae={class:"dg-empty-icon"},Oe={class:"dg-empty-title"},Te={class:"dg-empty-subtitle"},Ie="Lancez une recherche ou ajustez vos filtres pour afficher des résultats.",$e={__name:"DataGrid",props:{rowData:{type:Array,default:()=>[]},excludedColumns:{type:Array,default:()=>["ndoc"]},entityImages:{type:Object,default:()=>({})},clientImages:{type:Object,default:()=>({})},customStatusColors:{type:Function,default:null},documentNumberFields:{type:Array,default:()=>[]},entityNameFields:{type:Array,default:()=>[]},clientNameFields:{type:Array,default:()=>[]},validationFields:{type:Array,default:()=>[]},statusField:{type:String,default:"statut"},gridStyle:{type:String,default:"height: 100%; width: 100%"},rowHeight:{type:Number,default:void 0},enableTotals:{type:Boolean,default:!0},numericColumns:{type:Array,default:()=>[]},totalsColumns:{type:Array,default:()=>[]},aggregationTypes:{type:Object,default:()=>({})},columnWidths:{type:Object,default:()=>({})},customRenderers:{type:Object,default:()=>({})},columnOverrides:{type:Object,default:()=>({})},pinnedRightColumns:{type:Array,default:()=>[]},columnOrder:{type:Array,default:()=>[]},visibleColumns:{type:Array,default:()=>[]},conditionalColumns:{type:Object,default:()=>({})},disableSorting:{type:Boolean,default:!1},unsortableColumns:{type:Array,default:()=>[]},hiddenColumns:{type:Array,default:()=>[]},dateFormats:{type:Object,default:()=>({})},dateOnly:{type:Array,default:()=>[]},dateOnlyAll:{type:Boolean,default:!1},dateColumns:{type:Array,default:()=>[]},imageKeyField:{type:String,default:"ndoc"},entityImageSize:{type:Number,default:24},entityImageRounded:{type:Boolean,default:!0},getRowClass:{type:Function,default:null},getRowStyle:{type:Function,default:null},getCellClass:{type:Function,default:null},showCheckbox:{type:Boolean,default:!0},isRowSelectable:{type:Function,default:null},enableFilter:{type:Boolean,default:!0},autoSizeColumns:{type:Boolean,default:!1},columnTitles:{type:Object,default:()=>({})},excelFileName:{type:String,default:""},excelSheetName:{type:String,default:""},emptyIcon:{type:String,default:"pi pi-inbox"},emptyTitle:{type:String,default:"Aucune donnée à afficher"},emptySubtitle:{type:String,default:""},loading:{type:Boolean,default:!1},skeletonRowCount:{type:Number,default:12}},emits:["grid-ready","first-data-rendered","row-clicked","row-double-clicked","selection-changed","filter-changed","sort-changed"],setup(d,{expose:T,emit:I}){const e=d,N=z(!1),G=ge(),k=c(()=>e.loading||G.state.afficher_in_progress),H=c(()=>N.value&&(!e.rowData||e.rowData.length===0)),t=["18%","22%","14%","14%","16%","16%"],r=(l,s)=>{const y=(l*7+s*13)%5;return["55%","70%","80%","65%","75%"][y]},i=I,{isNumericColumn:g,isDateColumn:S,defaultColDef:w,excelStyles:A,calculerTotaux:v,getContextMenuItems:O,createGridEventHandlers:u}=xe(),{applyRenderers:F,createNumericRenderer:C,createDateRenderer:V}=Re(),Y=c(()=>({mode:"multiRow",checkboxes:e.showCheckbox,headerCheckbox:e.showCheckbox,enableClickSelection:!1,...e.isRowSelectable&&{isRowSelectable:e.isRowSelectable}})),ee=l=>e.columnTitles[l]?e.columnTitles[l]:l==="date_ech"?"Date échéance":l.charAt(0).toUpperCase()+l.slice(1).replace(/_/g," ").replace(/([A-Z])/g," $1").trim(),h=z(),m=z(),b=z([]),K=c(()=>Object.keys(e.entityImages).length>0?e.entityImages:e.clientImages),B=c(()=>e.entityNameFields.length>0?e.entityNameFields:e.clientNameFields),te=c(()=>{if(!e.rowData||e.rowData.length===0)return[];const l=e.rowData[0],s=[];let y;if(e.visibleColumns.length>0)y=e.visibleColumns.filter(a=>Object.prototype.hasOwnProperty.call(l,a));else if(e.columnOrder.length>0){const a=e.columnOrder.filter(D=>Object.prototype.hasOwnProperty.call(l,D)),p=Object.keys(l).filter(D=>!e.columnOrder.includes(D));y=[...a,...p]}else y=Object.keys(l);return y.forEach(a=>{if(e.excludedColumns.includes(a)||e.hiddenColumns.includes(a)||e.conditionalColumns[a]&&!e.conditionalColumns[a]())return;const p=e.dateColumns.length>0?e.dateColumns.includes(a):S(a),D=a.includes("."),n={field:D?void 0:a,colId:a,headerName:ee(a),sortable:!e.disableSorting&&!e.unsortableColumns.includes(a),filter:e.enableFilter?p?"agDateColumnFilter":"agTextColumnFilter":!1,floatingFilter:!1,resizable:!0,...D&&{valueGetter:o=>o.data?.[a]}};if(e.columnWidths[a]){const o=e.columnWidths[a];typeof o=="number"?n.width=o:typeof o=="object"&&(o.width&&(n.width=o.width),o.minWidth&&(n.minWidth=o.minWidth),o.maxWidth&&(n.maxWidth=o.maxWidth),o.flex&&(n.flex=o.flex))}else!(e.numericColumns.length>0?e.numericColumns.includes(a):g(a))&&!p&&(n.width=140);if(F(n,a,{clientImages:K.value,customStatusColors:e.customStatusColors,documentNumberFields:e.documentNumberFields,entityNameFields:B.value,validationFields:e.validationFields,statusField:e.statusField,imageKeyField:e.imageKeyField,entityImageSize:e.entityImageSize,entityImageRounded:e.entityImageRounded}),p){n.width=n.width||120,n.filter="agDateColumnFilter";const o=e.dateFormats[a],M=e.dateOnly.includes(a)||e.dateOnlyAll;o==="dateOnly"||M?n.valueFormatter=U=>U.value?be(U.value):"":n.valueFormatter=V()}else(e.numericColumns.length>0?e.numericColumns.includes(a):g(a))?(n.width=n.width||130,n.type="numericColumn",n.headerClass="numeric-header-custom",n.cellClass="ag-right-aligned-cell",n.cellRenderer=C()):(!n.width&&!n.flex&&(n.width=140),n.valueFormatter=o=>o.node?.rowPinned?o.value!=null&&o.value!==""?String(o.value):"":o.value);e.getCellClass&&(n.cellClass=e.getCellClass),e.customRenderers[a]&&(n.cellRenderer=e.customRenderers[a]),e.pinnedRightColumns.includes(a)&&(n.pinned="right"),e.columnOverrides[a]&&Object.assign(n,e.columnOverrides[a]),s.push(n)}),s}),$=c(()=>e.totalsColumns.length>0?e.totalsColumns:e.numericColumns),le=l=>e.enableTotals?O(l,b,h,c(()=>e.rowData),$.value,e.aggregationTypes):["copy","copyWithHeaders","separator","export"],E=u(m,c(()=>e.rowData),b,h,$.value,e.aggregationTypes,e.documentNumberFields),ae=l=>{E.onGridReady(l),N.value=!0,i("grid-ready",l)},ne=l=>{l.api&&(l.api.redrawRows(),e.autoSizeColumns&&l.api.autoSizeAllColumns()),i("first-data-rendered",l)},re=l=>{const s=E.onSelectionChanged(l);i("selection-changed",{event:l,selectedRows:s})},L=()=>{E.onFilterChanged(),i("filter-changed")},oe=l=>{E.onRowClick(l,s=>{i("row-clicked",{event:l,ndoc:s,rowIndex:l.rowIndex})})},se=l=>{i("row-double-clicked",{event:l,data:l.data})},q=()=>{const s=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");return{fileName:`${e.excelFileName||"Export"}_${s}.xlsx`,sheetName:e.excelSheetName||"Données",exportedRows:"filteredAndSorted",onlySelected:!1,suppressTextAsCDATA:!0,skipPinnedBottom:!0}},ie=c(()=>q()),de=()=>{m.value&&(m.value.exportDataAsExcel(q()),Ce("export:excel",{fichier:e.excelFileName||"export",lignes:e.rowData?.length||0}))},ue=()=>m.value?.getSelectedRows()||[],ce=()=>{e.enableTotals&&(b.value=v(h,c(()=>e.rowData),$.value,e.aggregationTypes))},fe=()=>{b.value=[]};let P=null;return Z(K,()=>{P&&clearTimeout(P),P=setTimeout(()=>{m.value&&B.value.length>0&&m.value.refreshCells({columns:B.value,force:!0})},150)},{deep:!0}),Z(()=>e.rowData,l=>{setTimeout(()=>{h?.value?.api&&h.value.api.redrawRows()},50),e.enableTotals&&l&&l.length>0&&setTimeout(()=>{b.value.length>0&&h?.value?.api&&(b.value=v(h,c(()=>e.rowData),$.value,e.aggregationTypes))},100)}),T({exportToExcel:de,getSelectedRows:ue,getDisplayedData:()=>{if(!m.value)return[];const l=[];return m.value.forEachNodeAfterFilterAndSort(s=>{s.data&&l.push(s.data)}),l},showTotals:ce,hideTotals:fe,gridApi:c(()=>m.value)}),(l,s)=>{const y=me("ag-grid-vue");return x(),R("div",{class:"ag-theme-quartz dg-wrapper",style:j(d.gridStyle)},[ye(y,{ref_key:"agGrid",ref:h,localeText:l.$agGridLocale,rowData:d.rowData,columnDefs:te.value,defaultColDef:J(w),theme:l.$agGridTheme,rowSelection:Y.value,suppressRowClickSelection:!1,pinnedBottomRowData:b.value,getContextMenuItems:le,defaultExcelExportParams:ie.value,excelStyles:J(A),getRowClass:d.getRowClass,getRowStyle:d.getRowStyle,rowHeight:d.rowHeight,suppressScrollOnNewData:!0,suppressNoRowsOverlay:!0,onGridReady:ae,onFirstDataRendered:ne,onRowClicked:oe,onRowDoubleClicked:se,onSelectionChanged:re,onFilterChanged:L,onSortChanged:L,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","rowSelection","pinnedBottomRowData","defaultExcelExportParams","excelStyles","getRowClass","getRowStyle","rowHeight"]),k.value?(x(),R("div",Se,[f("div",Fe,[(x(),R(W,null,_(6,a=>f("div",{key:`sh-${a}`,class:"dg-skeleton-cell",style:j({width:t[a-1]})},[...s[0]||(s[0]=[f("div",{class:"dg-skeleton-bar dg-skeleton-bar--header"},null,-1)])],4)),64))]),(x(!0),R(W,null,_(d.skeletonRowCount,a=>(x(),R("div",{key:`sr-${a}`,class:"dg-skeleton-row"},[(x(),R(W,null,_(6,p=>f("div",{key:`src-${a}-${p}`,class:"dg-skeleton-cell",style:j({width:t[p-1]})},[f("div",{class:"dg-skeleton-bar",style:j({width:r(a,p)})},null,4)],4)),64))]))),128))])):Q("",!0),!k.value&&H.value?(x(),R("div",De,[f("div",Ne,[f("div",Ae,[s[1]||(s[1]=f("span",{class:"dg-empty-ring"},null,-1)),s[2]||(s[2]=f("span",{class:"dg-empty-ring dg-empty-ring--delay"},null,-1)),f("i",{class:pe(d.emptyIcon)},null,2)]),f("p",Oe,X(d.emptyTitle),1),f("p",Te,X(d.emptySubtitle||Ie),1)])])):Q("",!0)],4)}}},Be=ve($e,[["__scopeId","data-v-e4821741"]]);export{Be as D};
