import e from"@babel/runtime/helpers/slicedToArray";import{useRef as t,useState as o,useEffect as r}from"react";import i from"prop-types";import{get as a,isEmpty as s}from"lodash";import{makeStyles as n,List as l,ListItem as c,ListItemText as d,Typography as p}from"@material-ui/core";import{jsxs as u,jsx as m}from"react/jsx-runtime";var g=n((function(e){return{assetListWrapper:{height:"calc(100% - 110px)",margin:"8px 0 4px",flex:1},assetListContainer:{maxHeight:function(e){var t=e.isTablet,o=e.isMobile;return t||!o?"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}}})),h=function(i){var n=i.page,h=i.loading,b=i.groupedAssets,f=i.onClickAsset,x=i.onScrollReached,y=i.isTablet,S=i.isMobile,v=g({isTablet:y,isMobile:S}),T=t(null),R=o("top"),w=e(R,2),I=w[0],k=w[1];r((function(){h||("top"===I&&T.current.scrollTo(0,5),"bottom"===I&&T.current.scrollTo(0,T.current.scrollHeight-T.current.offsetHeight-5))}),[h]);return u("div",{className:v.assetListWrapper,children:[m("div",{className:v.topShadow,children:" "}),u(l,{className:v.assetListContainer,subheader:m("li",{}),onScroll:function(t){if(t.target.scrollHeight!==t.target.offsetHeight){var o=t.target.scrollTop+t.target.offsetHeight;Math.abs(t.target.scrollHeight-o)<1&&b.find((function(t){var o=e(t,2);return o[0],40===o[1].length}))&&(k("top"),x("bottom")),0===Math.round(t.target.scrollTop)&&n>1&&(k("bottom"),x("top"))}},ref:T,children:[b.map((function(t){var o=e(t,2),r=o[0],i=o[1];return m("li",{className:v.listSection,children:m("ul",{className:v.ul,children:i.map((function(e){return m(c,{"data-testid":"".concat("AssetResultSection","_item_").concat(e.name,"MenuItem"),button:!0,classes:{gutters:v.listGutters},disabled:!e.redirectAssetId,onClick:function(){return f(e)},children:m(d,{primary:e.name,classes:{root:v.assetItemTextRoot,primary:v.assetItemTextPrimary}})},"item-".concat(r,"-").concat(a(e,"asset_id")?a(e,"asset_id"):a(e,"id")))}))})},"section-".concat(r))})),!h&&s(b)&&m("div",{className:v.empty,children:"Your search did not match any Asset Name"})]}),h&&m(p,{"data-testid":"".concat("AssetResultSection","_loading"),className:v.loadingInfo,children:"Loading..."}),m("div",{className:v.bottomShadow,children:" "})]})};h.propTypes={page:i.number.isRequired,loading:i.bool.isRequired,groupedAssets:i.arrayOf([]).isRequired,onClickAsset:i.func.isRequired,onScrollReached:i.func.isRequired,isTablet:i.bool.isRequired,isMobile:i.bool.isRequired};export{h as default};
