import t from"@babel/runtime/helpers/slicedToArray";import{useRef as e,useState as r,useEffect as o}from"react";import a from"prop-types";import{get as i,isEmpty as s}from"lodash";import{makeStyles as n,List as l,ListSubheader as c,Chip as p,ListItem as d,ListItemText as u,Typography as m}from"@material-ui/core";import{SEARCH_CATEGORIES as f}from"./constants.js";import{jsxs as g,jsx as h}from"react/jsx-runtime";var x=n((function(t){return{assetListWrapper:{margin:"8px 0",flex:1},assetListContainer:{maxHeight:"350px",backgroundColor:t.palette.background.paper,position:"relative",overflow:"auto"},listSection:{backgroundColor:"inherit"},ul:{backgroundColor:"inherit",padding:0},listGutters:{padding:"2px 8px"},assetTypeSubheaderChip:{height:"24px",color:t.palette.primary.text6},assetItemTextRoot:{minWidth:"300px"},assetItemTextPrimary:{overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},loadingInfo:{textAlign:"center",fontSize:"12px",lineHeight:"17px",color:t.palette.primary.text8},empty:{color:t.palette.primary.text6,fontSize:"12px",fontStyle:"italic",marginLeft:"8px"}}})),b=function(a){var n=a.page,b=a.loading,y=a.groupedAssets,S=a.onClickAsset,v=a.onScrollReached,T=x(),R=e(null),A=r("top"),C=t(A,2),H=C[0],I=C[1];o((function(){b||("top"===H&&R.current.scrollTo(0,5),"bottom"===H&&R.current.scrollTo(0,R.current.scrollHeight-R.current.offsetHeight-5))}),[b]);return g("div",{className:T.assetListWrapper,children:[g(l,{className:T.assetListContainer,subheader:h("li",{}),onScroll:function(e){if(e.target.scrollHeight!==e.target.offsetHeight){var r=e.target.scrollTop+e.target.offsetHeight;Math.abs(e.target.scrollHeight-r)<1&&y.find((function(e){var r=t(e,2);return r[0],40===r[1].length}))&&(I("top"),v("bottom")),0===Math.round(e.target.scrollTop)&&n>1&&(I("bottom"),v("top"))}},ref:R,children:[y.map((function(e){var r=t(e,2),o=r[0],a=r[1];return h("li",{className:T.listSection,children:g("ul",{className:T.ul,children:[h(c,{classes:{gutters:T.listGutters},children:h(p,{className:T.assetTypeSubheaderChip,variant:"outlined",label:f[o].labelPlural},o)}),a.map((function(t){return h(d,{"data-testid":"".concat("AssetResultSection","_item_").concat(t.name,"MenuItem"),button:!0,classes:{gutters:T.listGutters},disabled:!t.redirectAssetId,onClick:function(){return S(t)},children:h(u,{primary:t.name,classes:{root:T.assetItemTextRoot,primary:T.assetItemTextPrimary}})},"item-".concat(o,"-").concat(i(t,"asset_id")?i(t,"asset_id"):i(t,"id")))}))]})},"section-".concat(o))})),s(y)&&h("div",{className:T.empty,children:"Your search did not match any Asset Name"})]}),b&&h(m,{"data-testid":"".concat("AssetResultSection","_loading"),className:T.loadingInfo,children:"Loading..."})]})};b.propTypes={page:a.number.isRequired,loading:a.bool.isRequired,groupedAssets:a.arrayOf(a.array).isRequired,onClickAsset:a.func.isRequired,onScrollReached:a.func.isRequired};export{b as default};
//# sourceMappingURL=AssetResultSection.js.map
