"use strict";var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),r=require("prop-types"),s=require("lodash"),a=require("@material-ui/core"),i=require("./constants.js"),o=require("react/jsx-runtime");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=l(e),c=l(r),u=a.makeStyles((function(e){return{assetListWrapper:{margin:"8px 0",flex:1},assetListContainer:{maxHeight:"350px",backgroundColor:e.palette.background.paper,position:"relative",overflow:"auto"},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"}}})),d=function(e){var r=e.page,l=e.loading,c=e.groupedAssets,d=e.onClickAsset,p=e.onScrollReached,f=u(),m=t.useRef(null),g=t.useState("top"),h=n.default(g,2),x=h[0],y=h[1];t.useEffect((function(){l||("top"===x&&m.current.scrollTo(0,5),"bottom"===x&&m.current.scrollTo(0,m.current.scrollHeight-m.current.offsetHeight-5))}),[l]);return o.jsxs("div",{className:f.assetListWrapper,children:[o.jsxs(a.List,{className:f.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&&c.find((function(e){var t=n.default(e,2);return t[0],40===t[1].length}))&&(y("top"),p("bottom")),0===Math.round(e.target.scrollTop)&&r>1&&(y("bottom"),p("top"))}},ref:m,children:[c.map((function(e){var t=n.default(e,2),r=t[0],l=t[1];return o.jsx("li",{className:f.listSection,children:o.jsxs("ul",{className:f.ul,children:[o.jsx(a.ListSubheader,{classes:{gutters:f.listGutters},children:o.jsx(a.Chip,{className:f.assetTypeSubheaderChip,variant:"outlined",label:i.SEARCH_CATEGORIES[r].labelPlural},r)}),l.map((function(e){return o.jsx(a.ListItem,{"data-testid":"".concat("AssetResultSection","_item_").concat(e.name,"MenuItem"),button:!0,classes:{gutters:f.listGutters},disabled:!e.redirectAssetId,onClick:function(){return d(e)},children:o.jsx(a.ListItemText,{primary:e.name,classes:{root:f.assetItemTextRoot,primary:f.assetItemTextPrimary}})},"item-".concat(r,"-").concat(s.get(e,"asset_id")?s.get(e,"asset_id"):s.get(e,"id")))}))]})},"section-".concat(r))})),s.isEmpty(c)&&o.jsx("div",{className:f.empty,children:"Your search did not match any Asset Name"})]}),l&&o.jsx(a.Typography,{"data-testid":"".concat("AssetResultSection","_loading"),className:f.loadingInfo,children:"Loading..."})]})};d.propTypes={page:c.default.number.isRequired,loading:c.default.bool.isRequired,groupedAssets:c.default.arrayOf(c.default.array).isRequired,onClickAsset:c.default.func.isRequired,onScrollReached:c.default.func.isRequired},module.exports=d;
