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