<template>
	<div
		v-if="tag.poster"
		class="tile"
	>
		<router-link
			:to="{ name: 'tag', params: { tagSlug: tag.slug, range: 'latest' } }"
			:title="tag.name"
			class="poster-link"
		>
			<img
				v-if="!lazy && !sfw"
				:src="`/img/${tag.poster.thumbnail}`"
				:title="tag.poster.comment"
				:alt="tag.name"
				class="poster"
			>

			<img
				v-if="!lazy && sfw"
				:src="`/img/${tag.poster.sfw.thumbnail}`"
				:title="tag.poster.sfw.comment"
				:alt="tag.name"
				class="poster"
			>

			<img
				v-if="lazy && !sfw"
				:data-src="`/img/${tag.poster.thumbnail}`"
				:data-loading="`/img/${tag.poster.lazy}`"
				:title="tag.poster.comment"
				:alt="tag.name"
				class="poster"
			>

			<img
				v-if="lazy && sfw"
				:data-src="`/img/${tag.poster.sfw.thumbnail}`"
				:data-loading="`/img/${tag.poster.sfw.lazy}`"
				:title="tag.poster.sfw.comment"
				:alt="tag.name"
				class="poster"
			>
		</router-link>

		<router-link
			class="title"
			:to="{ name: 'tag', params: { tagSlug: tag.slug, range: 'latest' } }"
			:title="tag.name"
		>{{ tag.name }}</router-link>
	</div>

	<span
		v-else
		class="title"
	>{{ tag.name }}</span>
</template>

<script>
function sfw() {
	return this.$store.state.ui.sfw;
}

export default {
	props: {
		tag: {
			type: Object,
			default: null,
		},
		lazy: {
			type: Boolean,
			default: false,
		},
	},
	computed: {
		sfw,
	},
};
</script>

<style lang="scss" scoped>
@import 'theme';

.tile {
    box-sizing: border-box;
    position: relative;
	text-decoration: none;
}

.poster {
    width: 100%;
    box-shadow: 0 0 3px var(--darken-weak);
}

.title {
	display: inline-block;
    box-sizing: border-box;
    padding: .25rem .5rem .25rem 1rem;
	overflow: hidden;
	white-space: nowrap;
    color: var(--shadow-strong);
	text-decoration: none;
    font-weight: bold;
    text-transform: capitalize;
	text-overflow: ellipsis;
}

.poster-link:hover + .title,
.title:hover {
	color: var(--primary)
}

.poster-link:hover .poster {
	box-shadow: 0 0 3px var(--darken);
}
</style>
