import{_ as X}from"./vendor-pdf-b2a5d8b1.js";import{q as L,j as e,T as U,I as E}from"./vendor-mui-69397583.js";import{co as J,cp as Q,w as Y}from"./index-c62ac197.js";import{D as Z,i as R,E as q,j as K,k as ee,P as te,g as P,C as ae,d as re,F as se,H as oe,S as ne,G as ie,l as le,T as ce,I as x,m as de}from"./vendor-devex-33a39e11.js";import{s as xe}from"./FileSaver.min-20f3f13a.js";import{r as m}from"./vendor-react-ece1c85f.js";import{D as me}from"./DensitySelector-a2c1c68f.js";import{N as ue}from"./NoData-8c485a3a.js";const fe=["xlsx"];function pe({gridId:n}){return`${Y}:${n}`}L({palette:{primary:{main:"#1976d2"},secondary:{main:"#dc004e"}},typography:{fontFamily:"Roboto, Arial, sans-serif"}});const Fe=({columns:n,tableName:u="",data:i,id_label:f,selectedRowId:l,setSelectedRowId:S,setInLineFilters:y,setColSorting:C,isColumnReorderReq:b=!0,isSelectionReq:N=!0,isGroupingReq:_=!0,isEditingReq:A=!1,isColumnFilterReq:v=!0,isDataExportReq:T=!0,openFilter:z=null,isPaginationReq:h=!1,isFilterReq:B=!1,isCachingReq:O=!0,height:G,isLoading:g=!1})=>{const F=m.useMemo(()=>new Map(i==null?void 0:i.map(t=>[t[f],t])),[i,f]),k=m.useRef(null),M=m.useRef(null),$=[50,100,250,500,1e3,0],[w,I]=m.useState("standard"),H=m.useCallback(({selectedRowKeys:t})=>{if(t.length===l.length&&t.every((a,o)=>a===l[o]))return;const r=t==null?void 0:t.map(a=>F.get(a));S(r)},[F,l,S]),W=m.useCallback(t=>{var d,D;const{fullName:r,value:a}=t,o=parseInt(((d=r.match(/\d+/))==null?void 0:d[0])??"0",10),c=(D=t.component)==null?void 0:D.option("columns"),s=c==null?void 0:c[o];r.includes("sortOrder")?C(j=>({...j,sortBy:(s==null?void 0:s.dataField)||"",sortOrder:a||""})):(r.includes("filterValue")||r.includes("visible"))&&y(j=>[...j,{[s==null?void 0:s.dataField]:(a==null?void 0:a.trim())||""}])},[C,y]),V=async t=>{if(!n)return;const r=n.filter(a=>a.dataField!=="Action");if(t.format==="xlsx"){const{Workbook:a}=await X(()=>import("./vendor-excel-ee8fc4e5.js").then(s=>s.e),["assets/vendor-excel-ee8fc4e5.js","assets/vendor-react-ece1c85f.js","assets/vendor-devex-33a39e11.js","assets/vendor-mui-69397583.js"]),o=new a,c=o.addWorksheet("Main sheet");de({worksheet:c,component:t.component,columns:r}).then(()=>{const s=n.findIndex(d=>d.dataField==="Action");s!==-1&&c.spliceColumns(s+1,1),o.xlsx.writeBuffer().then(d=>{xe(new Blob([d],{type:"application/octet-stream"}),u?`${u}.xlsx`:"DataGrid.xlsx")})})}},p=!i||i.length===0;return e.jsx("div",{className:`dx-datagrid-density-${w}`,children:e.jsxs("div",{className:"relative",ref:M,children:[e.jsxs(Z,{noDataText:" ",ref:k,height:p&&!g?"auto":G||void 0,width:"100%",keyExpr:f,showBorders:!1,columnHidingEnabled:!1,allowColumnResizing:!0,columnResizingMode:"nextColumn",columnMinWidth:150,allowColumnReordering:b,remoteOperations:!0,selectedRowKeys:l==null?void 0:l.map(t=>t[f]),onExporting:V,onSelectionChanged:H,onOptionChanged:W,id:u,dataSource:i,children:[N&&e.jsx(R,{mode:"multiple"}),A&&e.jsx(q,{mode:"cell",allowUpdating:!0,allowAdding:!1,allowDeleting:!1}),O&&e.jsx(K,{enabled:!0,type:"localStorage",storageKey:pe({gridId:u})}),h&&e.jsx(ee,{defaultPageSize:50}),h&&e.jsx(te,{showPageSizeSelector:!0,allowedPageSizes:$,showNavigationButtons:!0,displayMode:"full",visible:h&&!p,showInfo:!0}),n==null?void 0:n.map((t,r)=>t.dataField==="Action"?e.jsx(P,{name:t.dataField,cellRender:a=>{const o=`${t.caption}`;return e.jsx("div",{"data-cname":o,className:t.cssClass,children:a.text})},...t,allowSorting:!1,allowFiltering:!1,allowSearch:!1},r):e.jsx(P,{cellRender:a=>{const o=`${t.caption}`;return e.jsx(U,{arrow:!0,title:a.text,componentsProps:{tooltip:{sx:{fontSize:"0.75rem",backgroundColor:"#333",color:"#fff",borderRadius:"4px"}}},children:e.jsx("div",{"data-cname":o,className:t.cssClass,children:a.text})})},...t},r)),b&&e.jsx(ae,{enabled:!0,mode:"select",children:e.jsx(re,{my:"right top",at:"right bottom",of:".dx-datagrid-column-chooser-button"})}),v&&e.jsx(se,{visible:!0}),e.jsx(oe,{visible:v,allowSearch:!1}),e.jsx(ne,{visible:!0,width:240,placeholder:"Search..."}),e.jsx(ie,{visible:_}),T&&e.jsx(le,{enabled:!0,formats:fe}),e.jsxs(ce,{children:[e.jsx(x,{location:"before",name:"searchPanel"}),B&&e.jsx(x,{location:"after",children:e.jsx(E,{onClick:z,children:e.jsx(J,{style:{fontSize:20}})})}),e.jsx(x,{location:"after",text:"Clear Filter",children:e.jsx(E,{title:"Clear Filter",onClick:()=>{var t;return(t=k.current.instance())==null?void 0:t.clearFilter()},children:e.jsx(Q,{style:{fontSize:18}})})}),e.jsx(x,{location:"after",children:e.jsx(me,{density:w,setDensity:I})}),e.jsx(x,{name:"exportButton"}),e.jsx(x,{name:"columnChooserButton"})]})]}),!p&&g&&e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-gray-500"}),e.jsx("span",{className:"text-gray-500 text-sm",children:"Loading..."})]})}),p&&!g&&e.jsx(ue,{})]})})};export{Fe as D};
