<template>
	<div
		v-if="tag.poster"
		class="tile"
	>
		<router-link
			:to="`/tag/${tag.slug}`"
			:title="tag.name"
			class="poster-link"
		>
			<img
				v-if="!lazy && !sfw"
				:src="`/img/${tag.poster.thumbnail}`"
				:style="{ 'background-image': `url(/img/${tag.poster.lazy})` }"
				:title="comment"
				:alt="tag.name"
				class="poster"
			>

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

			<img
				v-if="lazy && !sfw"
				:src="`/img/${tag.poster.thumbnail}`"
				:style="{ 'background-image': `url(/img/${tag.poster.lazy})` }"
				:title="comment"
				:alt="tag.name"
				loading="lazy"
				class="poster"
			>

			<img
				v-if="lazy && sfw"
				:src="`/img/${tag.poster.sfw.thumbnail}`"
				:style="{ 'background-image': `url(/img/${tag.poster.sfw.lazy})` }"
				:title="tag.poster.sfw.comment"
				:alt="tag.name"
				loading="lazy"
				class="poster"
			>

			<Logo
				v-if="!sfw"
				:photo="tag.poster"
				favicon
			/>
		</router-link>

		<router-link
			class="title"
			:to="`/tag/${tag.slug}`"
			:title="tag.name"
		>{{ tag.name }}</router-link>
	</div>

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

<script>
import Logo from '../album/logo.vue';

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

export default {
	components: {
		Logo,
	},
	props: {
		tag: {
			type: Object,
			default: null,
		},
		lazy: {
			type: Boolean,
			default: false,
		},
	},
	data() {
		return {
			comment: this.tag.poster?.entity ? `${this.tag.poster.comment} for ${this.tag.poster.entity.name}` : this.tag.poster?.comment,
		};
	},
	computed: {
		sfw,
	},
};
</script>

<style lang="scss" scoped>
.tile {
    box-sizing: border-box;
    position: relative;
	text-decoration: none;
	font-size: 0;

	&:hover {
		.poster {
			box-shadow: 0 0 2px var(--darken);
		}

		.title {
			color: var(--primary);
		}
	}
}

.poster {
	display: inline-block;
    width: 100%;
	height: 13.5rem;
	object-fit: cover;
	background-size: cover;
	background-position: center;
    box-shadow: 0 0 3px var(--darken-weak);
}

.poster-link {
	position: relative;
}

.title {
	display: block;
    box-sizing: border-box;
    padding: .5rem;
	overflow: hidden;
	white-space: nowrap;
	color: var(--shadow-strong);
	text-decoration: none;
	font-size: .9rem;
    font-weight: bold;
    text-transform: capitalize;
	text-overflow: ellipsis;
}
</style>
