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