import{u as useSelector,r as reactExports,j as jsxRuntimeExports,ag as selectIsFullscreenEnabled,B as Box,q as mountPanel,Z as AvailableComponents}from"./js-core.esm4.js";import{u as selectors$2,s as selectActiveResourceTab,b as selectActiveResourceSearchValues,h as actions,v as useLibraryStatus,S as SHARED_TEXT$2}from"./js-core.esm40.js";import{E as EResourceTypeValue}from"./js-core.esm15.js";import{t as tableInfiniteScroll}from"./js-core.esm9.js";import{E as EmptySearch,R as ResourceCard}from"./js-core.esm104.js";import"./js-core.esm7.js";import{u as useDispatch}from"./js-core.esm12.js";import"./js-core.esm30.js";import"./js-core.esm28.js";import"./js-core.esm33.js";import"./js-core.esm37.js";function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=new Array(t);r<t;r++)a[r]=e[r];return a}function _array_with_holes(e){if(Array.isArray(e))return e}function _iterable_to_array_limit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var a,s,o=[],i=!0,n=!1;try{for(r=r.call(e);!(i=(a=r.next()).done)&&(o.push(a.value),!t||o.length!==t);i=!0);}catch(e){n=!0,s=e}finally{try{i||null==r.return||r.return()}finally{if(n)throw s}}return o}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _sliced_to_array(e,t){return _array_with_holes(e)||_iterable_to_array_limit(e,t)||_unsupported_iterable_to_array(e,t)||_non_iterable_rest()}function _unsupported_iterable_to_array(e,t){var r;if(e)return"string"==typeof e?_array_like_to_array(e,t):"Map"===(r="Object"===(r=Object.prototype.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_array_like_to_array(e,t):void 0}var itemHeight$1=150,rtf=new Intl.RelativeTimeFormat("en",{numeric:"auto"}),units=[["year",31536e6],["month",2592e6],["week",6048e5],["day",864e5],["hour",36e5],["minute",6e4]];function relativeFromNow(t){if(!t)return"—";var e=new Date(t).getTime()-Date.now();if(Number.isNaN(e))return"—";var r=!0,t=!1,a=void 0;try{for(var s,o=units[Symbol.iterator]();!(r=(s=o.next()).done);r=!0){var i=_sliced_to_array(s.value,2),n=i[0],l=i[1];if(Math.abs(e)>=l)return rtf.format(Math.round(e/l),n)}}catch(e){t=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(t)throw a}}return"just now"}var LibraryTile=function(e){var t,r=e.item,a=useDispatch(),s=useSelector(selectIsFullscreenEnabled),e=useLibraryStatus(r),o=null!=(o=r.summary)&&o.lastTrainedDateTime?relativeFromNow(r.summary.lastTrainedDateTime):void 0;return jsxRuntimeExports.jsx(Box,{sx:{width:"100%",height:"".concat(itemHeight$1,"px")},children:jsxRuntimeExports.jsx(ResourceCard,{height:"".concat(itemHeight$1,"px"),onClick:function(){var e,t=r.id;t&&(e="LIBRARY_DETAILS_PANEL-".concat(t),a(mountPanel({panelId:e,microFrontend:{name:AvailableComponents.LIBRARY_DETAILS_PANEL,config:{libraryId:t}},panelConfig:{panelId:e,type:"APP_BAR_PANEL_TEMPLATE",marginTop:s?0:55,marginStart:s?0:80,size:"large",parentPanelId:AvailableComponents.RESOURCE_CENTER,dimmed:0,dimmedStatus:"dimParent",borderBottom:!0}})))},cardType:EResourceTypeValue.library,name:null!=(t=r.name)?t:"",description:r.description,avatarUrl:r.coverImageUrl,status:e,libraryType:null==(t=r.libraryType)?void 0:t.label,entityCount:null!=(t=null==(e=r.summary)?void 0:e.entityCount)?t:0,lastTrained:o})})},selectItems=selectors$2.selectItems,selectHasMore=selectors$2.selectHasMore,selectOffset=selectors$2.selectOffset,selectReadStatus=selectors$2.selectReadStatus,TableInfiniteScroll=tableInfiniteScroll.jsx.TableInfiniteScroll,itemHeight=150,LibrariesTable=function(){var e=useDispatch(),t=useSelector(selectActiveResourceTab),t=!!useSelector(selectActiveResourceSearchValues)[t],r=useSelector(selectItems),a=useSelector(selectHasMore),s=useSelector(selectOffset),o=useSelector(selectReadStatus),i=reactExports.useCallback(function(){e(actions.libraries.readStart(null))},[e]),n=SHARED_TEXT$2.libraries.emptyState,l=SHARED_TEXT$2.libraries.errorState;return jsxRuntimeExports.jsx(TableInfiniteScroll,{testId:"os-resource-center-resources-libraries",hasMore:a,fetchMore:i,fetchOnMount:0===r.length,TableEmptyStateComponent:t?jsxRuntimeExports.jsx(EmptySearch,{}):void 0,offset:s,items:r,itemHeight:itemHeight,isLoading:"pending"===o,error:"failure"===o,TableRowComponent:LibraryTile,MessageEmptyState:jsxRuntimeExports.jsx(n,{}),MessageErrorState:jsxRuntimeExports.jsx(l,{})})};export{LibrariesTable,LibrariesTable as default};
