import{__assign as e,__spreadArray as t}from'./../../ext-esm/tslib/tslib.es6.js';import{jsx as r,Fragment as n,jsxs as i}from"react/jsx-runtime";import{useMemo as o,useEffect as a}from"react";import l from"prop-types";import s from"classnames";import{Table as u,Column as c,SortDirection as d}from"react-virtualized";import{withStyles as m,IconButton as h,Typography as f,Tooltip as g}from"@material-ui/core";import{Settings as p,Sort as b,ArrowUpward as y,ArrowDownward as w}from"@material-ui/icons";import{getUnitDisplay as S}from"../../utils/convert.js";function R(e,t){var r=e.find((function(e){return e.key===t}))||{},n=r.unitType,i=r.customUnit;return i?"(".concat(i,")"):n?"(".concat(S(n),")"):""}function x(e,t){return(e.find((function(e){return e.key===t}))||{}).headerLabelClassName||""}function v(e,t){return(e.find((function(e){return e.key===t}))||{}).headerLabelUnitClassName||""}var C=function(l){var m=l.columns,S=l.data,C=l.useColumnSetting,_=l.useFixedColumnWidth,z=l.onOpenSettingDlg,k=l.classes,T=l.width,q=l.height,I=l.headerHeight,N=l.rowHeight,L=l.showTopSettingIcon,D=l.customMuiStyles,H=l.isTopSettingIconShownAlways,B=l.CustomCellRenderer,W=l.customRowStyle,O=l.sort,j=l.sortBy,A=l.sortDirection,F=e(e({},k),D),K=o((function(){return{label:"",key:"setting",width:C?25:0}}),[C]),V=o((function(){return m.filter((function(e){return e.show}))}),[m]),M=o((function(){return C?t(t([],V,!0),[K],!1):V}),[V,C,K]),E=o((function(){var e;if(T<=0)return{};var t=((e={})[K.key]=K.width,e),r=[];return V.filter((function(e){return Number.isFinite(e.width)})).forEach((function(e){t[e.key]=e.width-1,r.push(e.width-1)})),V.filter((function(e){return!Number.isFinite(e.width)})).forEach((function(e){var n=r.reduce((function(e,t){return e+t}),0),i=Math.floor((T-n-K.width)/(V.length-r.length)),o=e.minWidth||65,a=i<o?o:i;t[e.key]=a-1,r.push(a-1)})),t}),[T,V,K]),G=o((function(){return Object.values(E).reduce((function(e,t){return e+t}),0)}),[E]),U=H||G-12.5>=T;a((function(){L(U)}),[U]);var P=function(t){var n=t.label,o=t.dataKey,a=j||A||O;return o===K.key?U?null:r(h,e({size:"small","aria-label":"customize columns",className:F.settingIcon,onClick:z},{children:r(p,{fontSize:"inherit"})})):i(f,e({variant:"body2",className:s(F.headerLabel,x(m,o))},{children:[n," ",r("span",e({className:s(F.unitLabel,v(m,o))},{children:R(m,o)})),a&&o!==j&&r(g,e({title:"Sort A-Z"},{children:r(b,{fontSize:"small",className:k.sortIcon})})),a&&o===j&&(A===d.ASC?r(y,{fontSize:"small",className:k.sortIcon}):r(w,{fontSize:"small",className:k.sortIcon}))]}))},Z=function(t){var n=t.dataKey,i=t.rowData;return B?r(B,{columnKey:n,value:i[n]}):r(f,e({variant:"body2",className:F.cellData},{children:i[n]}))};return r(n,{children:r(u,e({width:_?G:T,height:q,headerHeight:I,rowClassName:function(e){var t,r=e.index;return s(((t={})[F.oddRow]=r%2==1,t))},rowHeight:N,rowCount:S.length,rowGetter:function(e){var t=e.index;return S[t]},rowStyle:W||{},className:F.table,sort:O,sortBy:j,sortDirection:A},{children:M.map((function(e){return r(c,{width:E[e.key]||0,dataKey:e.key,label:e.label,headerRenderer:P,cellRenderer:Z},e.key)}))}))})},_={columns:l.arrayOf(l.shape({show:l.bool,minWidth:l.number,width:l.number,key:l.string,label:l.string})).isRequired,data:l.arrayOf(l.shape({})).isRequired,useColumnSetting:l.bool.isRequired,useFixedColumnWidth:l.bool.isRequired,headerHeight:l.number.isRequired,rowHeight:l.number.isRequired,width:l.number.isRequired,height:l.number.isRequired,onOpenSettingDlg:l.func.isRequired,showTopSettingIcon:l.func.isRequired,sort:l.func,sortBy:l.string,sortDirection:l.string,classes:l.shape({sortIcon:l.string}).isRequired,customMuiStyles:l.shape({table:l.string,oddRow:l.string,headerLabel:l.string,cellData:l.string,unitLabel:l.string,settingIcon:l.string}).isRequired,isTopSettingIconShownAlways:l.bool.isRequired,CustomCellRenderer:l.func,customRowStyle:l.func};C.propTypes=_,C.defaultProps={CustomCellRenderer:null,customRowStyle:null,sort:null,sortBy:null,sortDirection:null};var z=m((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"}}}))(C);export{C as VirtualizedTableComponent,z as default};
