import{u as Z}from"./useAgGridConfig-DxO2r97K.js";import{k as J,h as Q,j as X}from"./index-BSaHX2oa.js";import{e as d,w as Y,g as ee,o as te,c as le,a as ne,q as ae,G as re,r as T}from"./vendor-BDR7yMJi.js";function oe(){const c=t=>({Brouillons:{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"},Brouillon:{bg:"#6c757d",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"},v=(t=null)=>{const a=t||c;return s=>{if(!s.value)return"";if(s.node.rowPinned)return`<span style="font-weight: 600;">${s.value}</span>`;const i=a(s.value);return`<span style="
        background-color: ${i.bg};
        color: ${i.text};
        padding: 0.25rem 0.75rem;
        border-radius: 0.375rem;
        font-size: 0.75rem;
        font-weight: 600;
        white-space: nowrap;
      ">${s.value}</span>`}},b=()=>t=>{if(!t.value)return"";if(t.node.rowPinned)return`<span style="font-weight: 600;">${t.value}</span>`;const a=String(t.value).toLowerCase().trim();return a==="oui"||a==="yes"||a==="1"||a==="true"||a==="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>
        `:a==="non"||a==="no"||a==="0"||a==="false"||a==="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>`:"",f=(t,a="ndoc",s="/images/profile.png")=>i=>{if(!i.value)return"";const y=i.data[a]||i.data.code_client||i.data.code_frs||i.data.code;let m=s;return(i.data["Code article"]||i.data.code_art||i.data.code_article)&&(m="/images/article.png"),`
        <div style="display: flex; align-items: center; gap: 8px;">
          <img src="${(t?.value?t.value[y]:t?.[y])||m}"
               style="width: 24px; height: 24px; border-radius: 50%; object-fit: cover;"
               onerror="this.src='${m}'" />
          <span>${i.value}</span>
        </div>
      `};return{createStatusRenderer:v,createValidationRenderer:b,createDocumentNumberRenderer:e,createEntityRenderer:f,createNumericRenderer:()=>t=>{if(t.value===null||t.value===void 0||t.value===""||t.value==="null")return"";const a=parseFloat(t.value);return isNaN(a)?"":Q(a)},createDateRenderer:()=>t=>J(t.value),applyRenderers:(t,a,s={})=>{const{clientImages:i,customStatusColors:y,documentNumberFields:m=["N°Devis","Numéro","Numéro Facture"],entityNameFields:R=["Nom du client"],validationFields:F=["Validé","valide","Valid"],statusField:u="statut",imageKeyField:h="ndoc"}=s;if(a===u){t.cellRenderer=v(y),t.width=t.width||170;return}if(m.includes(a)){t.cellRenderer=e(),t.width=t.width||130;return}if(R.includes(a)){t.cellRenderer=f(i,h),t.width||(t.flex=t.flex||2,t.minWidth=t.minWidth||200);return}if(F.includes(a)||F.includes(t.headerName)){t.cellRenderer=b(),t.width=t.width||80,t.headerName="Validé";return}},getDefaultStatusColors:c}}const ue={__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:null},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:()=>({})},pinnedRightColumns:{type:Array,default:()=>[]},columnOrder:{type:Array,default:()=>[]},conditionalColumns:{type:Object,default:()=>({})},hiddenColumns:{type:Array,default:()=>[]},dateFormats:{type:Object,default:()=>({})},dateOnly:{type:Array,default:()=>[]},dateColumns:{type:Array,default:()=>[]},imageKeyField:{type:String,default:"ndoc"},getRowClass:{type:Function,default:null},getRowStyle:{type:Function,default:null},getCellClass:{type:Function,default:null},showCheckbox:{type:Boolean,default:!0},enableFilter:{type:Boolean,default:!0},autoSizeColumns:{type:Boolean,default:!1},columnTitles:{type:Object,default:()=>({})},excelFileName:{type:String,default:""},excelSheetName:{type:String,default:""}},emits:["grid-ready","first-data-rendered","row-clicked","row-double-clicked","selection-changed","filter-changed","sort-changed"],setup(c,{expose:v,emit:b}){const e=c,f=b,{isNumericColumn:S,isDateColumn:A,defaultColDef:O,calculerTotaux:t,getContextMenuItems:a,createGridEventHandlers:s}=Z(),{applyRenderers:i,createNumericRenderer:y,createDateRenderer:m}=oe(),R=d(()=>({mode:"multiRow",checkboxes:e.showCheckbox,headerCheckbox:e.showCheckbox,enableClickSelection:!1})),F=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(),u=T(),h=T(),p=T([]),G=d(()=>Object.keys(e.entityImages).length>0?e.entityImages:e.clientImages),P=d(()=>e.entityNameFields.length>0?e.entityNameFields:e.clientNameFields),B=d(()=>{if(!e.rowData||e.rowData.length===0)return[];const l=e.rowData[0],g=[];let w;if(e.columnOrder.length>0){const r=e.columnOrder.filter(C=>Object.prototype.hasOwnProperty.call(l,C)),x=Object.keys(l).filter(C=>!e.columnOrder.includes(C));w=[...r,...x]}else w=Object.keys(l);return w.forEach(r=>{if(e.excludedColumns.includes(r)||e.hiddenColumns.includes(r)||e.conditionalColumns[r]&&!e.conditionalColumns[r]())return;const x=e.dateColumns.length>0?e.dateColumns.includes(r):A(r),C=r.includes("."),n={field:C?void 0:r,colId:r,headerName:F(r),sortable:!0,filter:e.enableFilter?x?"agDateColumnFilter":"agTextColumnFilter":!1,floatingFilter:!1,resizable:!0,...C&&{valueGetter:o=>o.data?.[r]}};if(e.columnWidths[r]){const o=e.columnWidths[r];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(r):S(r))&&!x&&(n.width=140);if(i(n,r,{clientImages:G.value,customStatusColors:e.customStatusColors,documentNumberFields:e.documentNumberFields,entityNameFields:P.value,validationFields:e.validationFields,statusField:e.statusField,imageKeyField:e.imageKeyField}),x){n.width=n.width||120,n.filter="agDateColumnFilter";const o=e.dateFormats[r],$=e.dateOnly.includes(r);o==="dateOnly"||$?n.valueFormatter=I=>I.value?X(I.value):"":n.valueFormatter=m()}else(e.numericColumns.length>0?e.numericColumns.includes(r):S(r))?(n.width=n.width||130,n.type="numericColumn",n.headerClass="numeric-header-custom",n.cellClass="ag-right-aligned-cell",n.cellRenderer=y()):(!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[r]&&(n.cellRenderer=e.customRenderers[r]),e.pinnedRightColumns.includes(r)&&(n.pinned="right"),g.push(n)}),g}),D=d(()=>e.totalsColumns.length>0?e.totalsColumns:e.numericColumns),W=l=>e.enableTotals?a(l,p,u,d(()=>e.rowData),D.value,e.aggregationTypes):["copy","copyWithHeaders","separator","export"],N=s(h,d(()=>e.rowData),p,u,D.value,e.aggregationTypes,e.documentNumberFields),z=l=>{N.onGridReady(l),f("grid-ready",l)},H=l=>{l.api&&(l.api.redrawRows(),e.autoSizeColumns&&l.api.autoSizeAllColumns()),f("first-data-rendered",l)},_=l=>{const g=N.onSelectionChanged(l);f("selection-changed",{event:l,selectedRows:g})},E=()=>{N.onFilterChanged(),f("filter-changed")},K=l=>{N.onRowClick(l,g=>{f("row-clicked",{event:l,ndoc:g,rowIndex:l.rowIndex})})},V=l=>{f("row-double-clicked",{event:l,data:l.data})},j=()=>{const g=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");return{fileName:`${e.excelFileName||"Export"}_${g}.xlsx`,sheetName:e.excelSheetName||"Données",exportedRows:"filteredAndSorted",onlySelected:!1,suppressTextAsCDATA:!0,skipPinnedBottom:!0}},k=d(()=>j()),q=()=>{h.value&&h.value.exportDataAsExcel(j())},M=()=>h.value?.getSelectedRows()||[],U=()=>{e.enableTotals&&(p.value=t(u,d(()=>e.rowData),D.value,e.aggregationTypes))},L=()=>{p.value=[]};return Y(()=>e.rowData,l=>{setTimeout(()=>{u?.value?.api&&u.value.api.redrawRows()},50),e.enableTotals&&l&&l.length>0&&setTimeout(()=>{p.value.length>0&&u?.value?.api&&(p.value=t(u,d(()=>e.rowData),D.value,e.aggregationTypes))},100)},{deep:!0}),v({exportToExcel:q,getSelectedRows:M,showTotals:U,hideTotals:L,gridApi:d(()=>h.value)}),(l,g)=>{const w=ee("ag-grid-vue");return te(),le("div",{class:"ag-theme-quartz",style:re(c.gridStyle)},[ne(w,{ref_key:"agGrid",ref:u,localeText:l.$agGridLocale,rowData:c.rowData,columnDefs:B.value,defaultColDef:ae(O),theme:l.$agGridTheme,rowSelection:R.value,suppressRowClickSelection:!1,pinnedBottomRowData:p.value,getContextMenuItems:W,defaultExcelExportParams:k.value,getRowClass:c.getRowClass,getRowStyle:c.getRowStyle,rowHeight:c.rowHeight,suppressScrollOnNewData:!0,onGridReady:z,onFirstDataRendered:H,onRowClicked:K,onRowDoubleClicked:V,onSelectionChanged:_,onFilterChanged:E,onSortChanged:E,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","rowSelection","pinnedBottomRowData","defaultExcelExportParams","getRowClass","getRowStyle","rowHeight"])],4)}}};export{ue as _};
