"use strict";var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),i=require("prop-types"),r=require("lodash"),a=require("@material-ui/core"),o=require("react/jsx-runtime");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=s(e),l=s(i),c=a.makeStyles((function(e){return{assetListWrapper:{height:"calc(100% - 110px)",margin:"8px 0 4px",flex:1},assetListContainer:{maxHeight:function(e){var t=e.isTablet,i=e.isMobile;return t||!i?"350px":"100% "},backgroundColor:e.palette.background.paper,position:"relative",overflowY:"auto",overFlowX:"hidden"},listSection:{backgroundColor:"inherit"},ul:{backgroundColor:"inherit",padding:0},listGutters:{padding:"2px 8px"},assetTypeSubheaderChip:{height:"24px",color:e.palette.primary.text6},assetItemTextRoot:{minWidth:"300px"},assetItemTextPrimary:{overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},loadingInfo:{textAlign:"center",fontSize:"12px",lineHeight:"17px",color:e.palette.primary.text8},empty:{color:e.palette.primary.text6,fontSize:"12px",fontStyle:"italic",marginLeft:"8px"},topShadow:{top:function(e){return e.isMobile?"170px":"111px"},width:"100%",height:"16px",backgroundImage:"linear-gradient(0deg, rgba(65, 65, 65, 0) 0%, ".concat(e.palette.background.b9," 100%)"),position:"absolute",zIndex:2},bottomShadow:{width:"100%",height:"15px",backgroundImage:"linear-gradient(180deg, rgba(65, 65, 65, 0) 0%, ".concat(e.palette.background.b9," 100%)"),position:"absolute",bottom:"16px",zIndex:2}}})),d=function(e){var i=e.page,s=e.loading,l=e.groupedAssets,d=e.onClickAsset,u=e.onScrollReached,p=e.isTablet,g=e.isMobile,m=c({isTablet:p,isMobile:g}),h=t.useRef(null),f=t.useState("top"),x=n.default(f,2),b=x[0],y=x[1];t.useEffect((function(){s||("top"===b&&h.current.scrollTo(0,5),"bottom"===b&&h.current.scrollTo(0,h.current.scrollHeight-h.current.offsetHeight-5))}),[s]);return o.jsxs("div",{className:m.assetListWrapper,children:[o.jsx("div",{className:m.topShadow,children:" "}),o.jsxs(a.List,{className:m.assetListContainer,subheader:o.jsx("li",{}),onScroll:function(e){if(e.target.scrollHeight!==e.target.offsetHeight){var t=e.target.scrollTop+e.target.offsetHeight;Math.abs(e.target.scrollHeight-t)<1&&l.find((function(e){var t=n.default(e,2);return t[0],40===t[1].length}))&&(y("top"),u("bottom")),0===Math.round(e.target.scrollTop)&&i>1&&(y("bottom"),u("top"))}},ref:h,children:[l.map((function(e){var t=n.default(e,2),i=t[0],s=t[1];return o.jsx("li",{className:m.listSection,children:o.jsx("ul",{className:m.ul,children:s.map((function(e){return o.jsx(a.ListItem,{"data-testid":"".concat("AssetResultSection","_item_").concat(e.name,"MenuItem"),button:!0,classes:{gutters:m.listGutters},disabled:!e.redirectAssetId,onClick:function(){return d(e)},children:o.jsx(a.ListItemText,{primary:e.name,classes:{root:m.assetItemTextRoot,primary:m.assetItemTextPrimary}})},"item-".concat(i,"-").concat(r.get(e,"asset_id")?r.get(e,"asset_id"):r.get(e,"id")))}))})},"section-".concat(i))})),!s&&r.isEmpty(l)&&o.jsx("div",{className:m.empty,children:"Your search did not match any Asset Name"})]}),s&&o.jsx(a.Typography,{"data-testid":"".concat("AssetResultSection","_loading"),className:m.loadingInfo,children:"Loading..."}),o.jsx("div",{className:m.bottomShadow,children:" "})]})};d.propTypes={page:l.default.number.isRequired,loading:l.default.bool.isRequired,groupedAssets:l.default.arrayOf([]).isRequired,onClickAsset:l.default.func.isRequired,onScrollReached:l.default.func.isRequired,isTablet:l.default.bool.isRequired,isMobile:l.default.bool.isRequired},module.exports=d;
//# sourceMappingURL=AssetResultSection.js.map
