import * as React from 'react';
import { BlueRain, BlueRainConsumer } from '@blueeast/bluerain-os';
import SuccessComponent from './SuccessComponent';
import emptyComponent from './EmptyComponent';
import getAppList from '../../helpers/getAppList';

const AppGrid = () => (
	<BlueRainConsumer>
		{(BR: BlueRain) => {
			// gets applist
			const appsList = getAppList(BR);

			const statefulProps = {
				data: () => appsList.length > 0,
				emptyComponent,
				isEmpty: () => appsList.length === 0,
				isLoading: () => false
			};
			return (
				<BR.Components.StatefulComponent {...statefulProps} >
					<SuccessComponent appsList={appsList} />
				</BR.Components.StatefulComponent>
			);
		}}
	</BlueRainConsumer>
);

export default AppGrid;