import{__assign as e,__spreadArray as t}from'./../../ext-esm/tslib/tslib.es6.js';import{jsx as n,Fragment as r,jsxs as i}from"react/jsx-runtime";import{useMemo as o,useEffect as l}from"react";import a from"classnames";import{Table as u,Column as c,SortDirection as s}from"react-virtualized";import{makeStyles as d,IconButton as m,Typography as f,Tooltip as h}from"@material-ui/core";import{Settings as p,Sort as g,ArrowUpward as b,ArrowDownward as y}from"@material-ui/icons";import{getUnitDisplay as w}from"../../utils/convert.js";var v=d((function(e){return{table:{"& .ReactVirtualized__Table__headerRow":{textTransform:"none",borderBottom:e.isLightTheme?"1px solid rgba(224, 224, 224, 1)":"1px solid rgba(81, 81, 81, 1)"},"& .ReactVirtualized__Table__row":{borderBottom:e.isLightTheme?"1px solid rgba(224, 224, 224, 1)":"1px solid rgba(81, 81, 81, 1)"},"& .ReactVirtualized__Table__Grid":{outline:"none"},"& .ReactVirtualized__Table__headerColumn":{outline:"none"}},oddRow:{backgroundColor:e.isLightTheme?"rgba(189, 189, 189, 0.1)":"#303030"},headerLabel:{lineHeight:"14px",fontSize:"12px",fontStyle:"normal",letterSpacing:"-0.25px",display:"flex",alignItems:"center",flexWrap:"wrap"},cellData:{lineHeight:"14px",fontSize:"12px",fontWeight:"normal",fontStyle:"normal",letterSpacing:"0.15px"},unitLabel:{fontSize:"10px",opacity:.5},settingIcon:{padding:"3px",fontSize:"20px"},sortIcon:{fontSize:"16px"}}}));function S(e,t){var n=e.find((function(e){return e.key===t}))||{},r=n.unitType,i=n.customUnit;return i?"(".concat(i,")"):r?"(".concat(w(r),")"):""}function x(e,t){return(e.find((function(e){return e.key===t}))||{}).headerLabelClassName||""}function _(e,t){return(e.find((function(e){return e.key===t}))||{}).headerLabelUnitClassName||""}var z=function(d){var w=d.columns,z=d.data,C=d.useColumnSetting,k=d.useFixedColumnWidth,N=d.onOpenSettingDlg,R=d.width,T=d.height,I=d.headerHeight,L=d.rowHeight,D=d.showTopSettingIcon,H=d.customMuiStyles,B=d.isTopSettingIconShownAlways,K=d.CustomCellRenderer,j=void 0===K?null:K,V=d.CustomHeaderCellRenderer,W=void 0===V?null:V,A=d.customRowStyle,F=void 0===A?null:A,E=d.sort,G=void 0===E?null:E,M=d.sortBy,O=void 0===M?null:M,U=d.sortDirection,Z=void 0===U?null:U,q=d.onScroll,J=void 0===q?function(){return null}:q,P=v(),Q=e(e({},P),H),X=o((function(){return{label:"",key:"setting",width:C?25:0}}),[C]),Y=o((function(){return w.filter((function(e){return e.show}))}),[w]),$=o((function(){return C?t(t([],Y,!0),[X],!1):Y}),[Y,C,X]),ee=o((function(){var e;if(R<=0)return{};var t=((e={})[X.key]=X.width,e),n=[];return Y.filter((function(e){return Number.isFinite(e.width)})).forEach((function(e){t[e.key]=e.width-1,n.push(e.width-1)})),Y.filter((function(e){return!Number.isFinite(e.width)})).forEach((function(e){var r=n.reduce((function(e,t){return e+t}),0),i=Math.floor((R-r-X.width)/(Y.length-n.length)),o=e.minWidth||65,l=i<o?o:i;t[e.key]=l-1,n.push(l-1)})),t}),[R,Y,X]),te=o((function(){return Object.values(ee).reduce((function(e,t){return e+t}),0)}),[ee]),ne=B||te-12.5>=R;l((function(){D(ne)}),[ne]);var re=function(e){var t=e.label,r=e.dataKey,o=O||Z||G;return W?n(W,{columnKey:r,columns:w,sortBy:O,sortDirection:Z}):r===X.key?ne?null:n(m,{size:"small","aria-label":"customize columns",className:Q.settingIcon,onClick:N,children:n(p,{fontSize:"inherit"})}):i(f,{variant:"body2",className:a(Q.headerLabel,x(w,r)),children:[t," ",n("span",{className:a(Q.unitLabel,_(w,r)),children:S(w,r)}),o&&r!==O&&n(h,{title:"Sort A-Z",children:n(g,{fontSize:"small",className:P.sortIcon})}),o&&r===O&&(Z===s.ASC?n(b,{fontSize:"small",className:P.sortIcon}):n(y,{fontSize:"small",className:P.sortIcon}))]})},ie=function(e){var t=e.dataKey,r=e.rowData;return j?n(j,{columnKey:t,value:r[t],columns:w}):n(f,{variant:"body2",className:Q.cellData,children:r[t]})};return n(r,{children:n(u,{width:k?te:R,height:T,headerHeight:I,rowClassName:function(e){var t,n=e.index;return a(((t={})[Q.oddRow]=n%2==1,t))},rowHeight:L,rowCount:z.length,rowGetter:function(e){var t=e.index;return z[t]},rowStyle:F||{},className:Q.table,sort:G,sortBy:O,sortDirection:Z,onScroll:J,children:$.map((function(e){return n(c,{width:ee[e.key]||0,dataKey:e.key,label:e.label,headerRenderer:re,cellRenderer:ie},e.key)}))})})};export{z as VirtualizedTableComponent,z as default};
