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 a}from"react";import l 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,k=d.useColumnSetting,N=d.useFixedColumnWidth,C=d.onOpenSettingDlg,R=d.width,T=d.height,I=d.headerHeight,L=d.rowHeight,D=d.showTopSettingIcon,H=d.customMuiStyles,j=d.isTopSettingIconShownAlways,B=d.CustomCellRenderer,K=void 0===B?null:B,V=d.customRowStyle,W=void 0===V?null:V,A=d.sort,F=void 0===A?null:A,E=d.sortBy,G=void 0===E?null:E,M=d.sortDirection,O=void 0===M?null:M,U=v(),Z=e(e({},U),H),q=o((function(){return{label:"",key:"setting",width:k?25:0}}),[k]),J=o((function(){return w.filter((function(e){return e.show}))}),[w]),P=o((function(){return k?t(t([],J,!0),[q],!1):J}),[J,k,q]),Q=o((function(){var e;if(R<=0)return{};var t=((e={})[q.key]=q.width,e),n=[];return J.filter((function(e){return Number.isFinite(e.width)})).forEach((function(e){t[e.key]=e.width-1,n.push(e.width-1)})),J.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-q.width)/(J.length-n.length)),o=e.minWidth||65,a=i<o?o:i;t[e.key]=a-1,n.push(a-1)})),t}),[R,J,q]),X=o((function(){return Object.values(Q).reduce((function(e,t){return e+t}),0)}),[Q]),Y=j||X-12.5>=R;a((function(){D(Y)}),[Y]);var $=function(e){var t=e.label,r=e.dataKey,o=G||O||F;return r===q.key?Y?null:n(m,{size:"small","aria-label":"customize columns",className:Z.settingIcon,onClick:C,children:n(p,{fontSize:"inherit"})}):i(f,{variant:"body2",className:l(Z.headerLabel,x(w,r)),children:[t," ",n("span",{className:l(Z.unitLabel,_(w,r)),children:S(w,r)}),o&&r!==G&&n(h,{title:"Sort A-Z",children:n(g,{fontSize:"small",className:U.sortIcon})}),o&&r===G&&(O===s.ASC?n(b,{fontSize:"small",className:U.sortIcon}):n(y,{fontSize:"small",className:U.sortIcon}))]})},ee=function(e){var t=e.dataKey,r=e.rowData;return K?n(K,{columnKey:t,value:r[t]}):n(f,{variant:"body2",className:Z.cellData,children:r[t]})};return n(r,{children:n(u,{width:N?X:R,height:T,headerHeight:I,rowClassName:function(e){var t,n=e.index;return l(((t={})[Z.oddRow]=n%2==1,t))},rowHeight:L,rowCount:z.length,rowGetter:function(e){var t=e.index;return z[t]},rowStyle:W||{},className:Z.table,sort:F,sortBy:G,sortDirection:O,children:P.map((function(e){return n(c,{width:Q[e.key]||0,dataKey:e.key,label:e.label,headerRenderer:$,cellRenderer:ee},e.key)}))})})};export{z as VirtualizedTableComponent,z as default};
