import React from 'react';
import { ContentCoverGridItem, ContentCount } from 'nixplay-ui-kit';
import PropTypes from 'prop-types';

import { EMAIL } from '~/store/contentTypes';


export const AlbumGridItem = (props) => {
	const { album } = props;
	const counts = [
		{ icon: 'photo-small', text: album.count },
	];

	const thumbs = [];
	if (album.cover.url) {
		thumbs.push(album.cover);
	} else if (album.thumbs[0]) {
		thumbs.push(album.thumbs[0]);
	}

	return (
		<ContentCoverGridItem
			{...props}
			thumbsHeight="short"
			name={album.name}
			testID={album.name}
			thumbs={thumbs}
			emptyIcon="album"
			openContent={() => { props.openAlbum(album.id); }}
		>
			{album.type === EMAIL &&
				<ContentCoverGridItem.IconStamp name="friends" color="white" backgroundColor="orange" />}
			<ContentCoverGridItem.Line2>
				<ContentCount counts={counts} />
			</ContentCoverGridItem.Line2>
		</ContentCoverGridItem>
	);
};

AlbumGridItem.propTypes = {
	album: PropTypes.object.isRequired,
	openAlbum: PropTypes.func,
};

AlbumGridItem.defaultProps = {
	openAlbum: () => {},
};
