<template>
	<div class="tile">
		<div class="movie">
			<router-link
				:to="{ name: 'movie', params: { movieId: movie.id, movieSlug: movie.slug } }"
				class="cover"
			>
				<img
					v-if="movie.covers[0]"
					:src="`/media/${movie.covers[0].thumbnail}`"
				>
			</router-link>

			<div class="info">
				<div class="details">
					<span
						v-if="movie.entity.type !== 'network' && !movie.entity.independent && movie.entity.parent"
						class="entity"
					>
						<router-link
							v-tooltip.bottom="`Part of ${movie.entity.parent.name}`"
							:title="`Part of ${movie.entity.parent.name}`"
							:to="`/${movie.entity.parent.type}/${movie.entity.parent.slug}`"
							class="entity-link"
						><img
							:src="`/img/logos/${movie.entity.parent.slug}/favicon.png`"
							class="favicon"
						></router-link>

						<router-link
							v-tooltip.bottom="`More from ${movie.entity.name}`"
							:title="`More from ${movie.entity.name}`"
							:to="`/${movie.entity.type}/${movie.entity.slug}`"
							class="entity-link"
						>{{ movie.entity.name }}</router-link>
					</span>

					<router-link
						v-else
						:to="`/${movie.entity.type}/${movie.entity.slug}`"
						class="entity entity-link"
					><img
						:src="`/img/logos/${movie.entity.slug}/favicon.png`"
						class="favicon"
					>{{ movie.entity.name }}</router-link>

					<a
						v-if="movie.date"
						v-tooltip.bottom="movie.url && `View movie on ${movie.entity.name}`"
						:title="movie.url && `View movie on ${movie.entity.name}`"
						:href="movie.url"
						:class="{ upcoming: isAfter(movie.date, new Date()) }"
						target="_blank"
						rel="noopener noreferrer"
						class="date"
					><Icon icon="share2" />{{ formatDate(movie.date, 'MMMM D, YYYY', movie.datePrecision) }}</a>

					<a
						v-else
						:href="movie.url"
						:class="{ upcoming: isAfter(movie.date, new Date()), new: movie.isNew }"
						title="Scene date N/A, showing date added"
						target="_blank"
						rel="noopener noreferrer"
						class="date"
					>{{ `(${formatDate(movie.dateAdded, 'MMMM D, YYYY')})` }}</a>
				</div>

				<router-link
					:to="{ name: 'movie', params: { movieId: movie.id, movieSlug: movie.slug } }"
					class="title-link"
				>
					<h3 class="title">{{ movie.title }}</h3>
				</router-link>

				<ul
					class="actors nolist"
					:title="movie.actors.map(actor => actor.name).join(', ')"
				>
					<li
						v-for="actor in movie.actors"
						:key="`tag-${movie.id}-${actor.id}`"
						class="actor"
					><router-link
						:to="`/actor/${actor.id}/${actor.slug}`"
						class="actor-link"
					>{{ actor.name }}</router-link></li>
				</ul>

				<ul
					class="tags nolist"
					:title="movie.tags.map(tag => tag.name).join(', ')"
				>
					<li
						v-for="tag in movie.tags"
						:key="`tag-${movie.id}-${tag.id}`"
						class="tag"
					><router-link
						:to="`/tag/${tag.slug}`"
						class="tag-link"
					>{{ tag.name }}</router-link></li>
				</ul>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	props: {
		movie: {
			type: Object,
			default: null,
		},
	},
};
</script>

<style lang="scss" scoped>
.tile {
	display: flex;
	flex-direction: column;
	background: var(--background);
	box-shadow: 0 0 3px var(--darken-weak);
	font-size: 0;
}

.movie {
	display: flex;
}

.title-link {
	color: var(--text);
	text-decoration: none;
}

.details {
	display: flex;
	justify-content: space-between;
	align-items: center;
	color: var(--text-light);
	background: var(--profile);
	padding: .5rem 1rem;
    font-size: .8rem;
	font-weight: bold;
}

.entity-link,
.date {
	display: flex;
	align-items: center;
	color: inherit;
	font-size: inherit;
	text-decoration: none;

	.favicon {
		width: 1rem;
		height: 1rem;
		margin: 0 .5rem 0 0;
	}

	.icon {
		fill: var(--highlight-weak);
		margin: 0 .25rem 0 0;
	}

	&:hover .icon {
		fill: var(--text-light);
	}
}

.cover {
	height: 16rem;
	box-shadow: 0 0 3px var(--darken-weak);

	img {
		height: 100%;
		max-width: 12rem;
		object-fit: cover;
		object-position: center ;
	}
}

.info {
	flex-grow: 1;
	overflow: hidden;
}

.title {
	box-sizing: border-box;
	padding: 1rem;
	margin: 0;
	font-size: 1rem;
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
}

.actors {
	padding: 0 1rem;
	margin: 0 0 1rem 0;
	line-height: 1.5;
}

.actor:not(:last-child)::after {
	content: ',';
	margin: 0 .25rem 0 0;
	font-size: 1rem;
}

.actor-link {
	font-size: 1rem;
	color: var(--link);
	text-decoration: none;

	&:hover {
		color: var(--primary);
	}
}

.tags {
	padding: .2rem 1rem 0 1rem;
	height: 1.75rem;
	line-height: 2;
	overflow: hidden;
}

.tag {
	margin: 0 0 .5rem 0;
}

.tag-link {
	background: var(--background);
	font-size: .75rem;
	padding: .25rem .5rem;
	color: var(--shadow);
	font-weight: bold;
	text-decoration: none;
	box-shadow: 0 0 3px var(--shadow-weak);

	&:hover {
		color: var(--primary);
	}
}
</style>
