<!--
  - @copyright Copyright (c) 2021 Jonas Heinrich
  -
  - @author Jonas Heinrich <onny@project-insanity.org>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->
<template>
	<div class="podcastSection">
		<div class="podcastSectionHeader">
			<h1>{{ title }}</h1>
		</div>
		<div class="grid">
			<div
				v-for="(podcast, idx) in podcasts"
				:key="idx"
				class="podcastCard">
				<router-link :to="{ path: `/browse/show/${podcast.id}`}">
					<div v-show="podcast.smallImageURL"
						v-lazy:background-image="podcast.smallImageURL"
						class="podcastImage" />
					<div v-show="podcast.imgurl"
						v-lazy:background-image="podcast.imgurl"
						class="podcastImage" />
					<span class="title">
						{{ podcast.title }}
					</span>
					<span class="subtitle">
						{{ podcast.author }}
					</span>
				</router-link>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	name: 'ItemGrid',
	props: {
		title: {
			type: String,
			default: '',
		},
		podcasts: {
			type: Object,
			default() { return {} },
		},
	},
}
</script>

<style lang="scss">

.podcastSection {
	margin-bottom: 20px;
}

.podcastSectionHeader {
	padding: 10px 0px;
	z-index: 60;
	position: sticky;
	top: 50px;
	background: white;
	display: flex;
	align-items: center;
	margin-bottom: 10px;

	h1 {
		flex-grow: 1;
		font-size: 1.6em;
	}
}

.grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.podcastCard {
	height: 220px;
	margin-right: 15px;
	flex-shrink: 0;
	background: rgba(241, 241, 241, 0.6);
	border-radius: 3px;
	padding: 15px;
	transition: all 0.2s ease-in-out;

	* {
		cursor: pointer;
	}

	.podcastImage {
		background-size: cover;
		background-position: center;
		box-shadow: 1px 1px 2px rgba(0,0,0,.5);
		border: 1px solid rgba(0,0,0,.5);
		border-radius: 5px;
		width: 140px;
		height: 140px;
		margin-bottom: 5px;
		transition: opacity .4s ease;
	}

	span {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: block;
	}
	span.title {
		font-size: 1em;
	}
	span.subtitle {
		font-size: 0.9em;
		color: #b5b1b1;
	}
}

.podcastCard:hover {
	background: rgb(236, 236, 236);
}
</style>