"use strict";var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),s=require("classnames"),r=require("prop-types"),i=require("lodash"),a=require("@material-ui/core"),l=require("../../../constants.js"),n=require("./constants.js"),u=require("react/jsx-runtime");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=o(e),d=o(s),p=o(r),f=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"},menuItem:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},allMenuItem:{boxShadow:"inset 0px -1px 0px rgba(255, 255, 255, 0.25)"},statusWrapper:{display:"flex",alignItems:"center",width:"102px"},status:{width:"8px",height:"8px",marginRight:"8px",borderRadius:"50%",cursor:"default"}}})),h=function(e){var s=e.subjectWellId,r=e.page,o=e.assetType,p=e.loading,h=e.groupedAssets,m=e.onClickAsset,g=e.onClickAllAsset,x=e.onScrollReached,b=f(),v=t.useRef(null),y=t.useState("top"),j=c.default(y,2),R=j[0],S=j[1],C=t.useState(0),A=c.default(C,2),I=A[0],k=A[1],q=i.sum(null==h?void 0:h.map((function(e){var t=c.default(e,2);t[0];var s=t[1];return(null==s?void 0:s.length)||0}))),T=t.useMemo((function(){if(1===h.length){var e=h[0][1],t=e.filter((function(e){return e.checked})).length;return[t>0&&e.length!==t,t===e.length]}return[!1,!1]}),[h]),H=c.default(T,2),N=H[0],w=H[1];t.useEffect((function(){p?k(q):("top"===R&&v.current.scrollTo(0,5),"bottom"===R&&v.current.scrollTo(0,v.current.scrollHeight-v.current.offsetHeight-5),"auto"===R&&v.current.scrollTo(0,(v.current.scrollHeight-v.current.offsetHeight)*I/q))}),[p]);return u.jsxs("div",{className:b.assetListWrapper,children:[u.jsxs(a.List,{className:b.assetListContainer,subheader:u.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&&!function(e,t){return!e.find((function(e){var s=c.default(e,2);return s[0],s[1].length===l.ROWS_PER_PAGE*t}))}(h,r)&&(S("auto"),x("bottom"))}},ref:v,children:[h.map((function(e){var t=c.default(e,2),r=t[0],p=t[1];return u.jsx("li",{className:b.listSection,children:u.jsxs("ul",{className:b.ul,children:[!o&&u.jsx(a.ListSubheader,{classes:{gutters:b.listGutters},children:u.jsx(a.Chip,{className:b.assetTypeSubheaderChip,variant:"outlined",label:n.SEARCH_CATEGORIES[r].labelPlural},r)}),o&&u.jsx(a.ListItem,{button:!0,classes:{gutters:b.listGutters},onClick:function(){return g(!w,r)},children:u.jsx("div",{className:d.default(b.menuItem,b.allMenuItem),children:u.jsxs("div",{children:[u.jsx(a.Checkbox,{checked:w,indeterminate:N,style:{marginRight:8}}),"All"]})})}),p.map((function(e){var t;return u.jsx(a.ListItem,{"data-testid":"".concat("AssetResultSection","_item_").concat(e.name,"MenuItem"),button:!0,classes:{gutters:b.listGutters},disabled:e.type===n.SEARCH_CATEGORIES.well.name&&!e.visibility.includes("visible")||!e.redirectAssetId||e.redirectAssetId===s,onClick:function(){return m(e,r)},children:u.jsxs("div",{className:b.menuItem,children:[u.jsxs("div",{children:[u.jsx(a.Checkbox,{checked:e.checked,style:{marginRight:8}}),e.name]}),u.jsxs("div",{className:b.statusWrapper,children:[u.jsx("div",{className:b.status,style:{background:null===(t=l.StatusOptions.find((function(t){return t.value===e.status})))||void 0===t?void 0:t.color}}),i.startCase(e.status)]})]})},"item-".concat(r,"-").concat(i.get(e,"asset_id")?i.get(e,"asset_id"):i.get(e,"id")))}))]})},"section-".concat(r))})),i.isEmpty(h)&&u.jsx("div",{className:b.empty,children:"Your search did not match any Asset Name"})]}),p&&u.jsx(a.Typography,{"data-testid":"".concat("AssetResultSection","_loading"),className:b.loadingInfo,children:"Loading..."})]})};h.propTypes={subjectWellId:p.default.number.isRequired,page:p.default.number.isRequired,assetType:p.default.string.isRequired,loading:p.default.bool.isRequired,groupedAssets:p.default.arrayOf(p.default.shape({})).isRequired,onClickAsset:p.default.func.isRequired,onClickAllAsset:p.default.func.isRequired,onScrollReached:p.default.func.isRequired},module.exports=h;
