<template>
	<router-link
		:to="{ name: 'tag', params: { tagSlug: tag.slug } }"
		:title="tag.name"
		class="tile"
	>
		<span class="title">{{ tag.name }}</span>

		<template v-if="tag.poster">
			<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"
			>
		</template>
	</router-link>
</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 {
    color: var(--text-light);
    background: var(--profile);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    box-sizing: border-box;
    position: relative;
    text-align: center;
    text-decoration: none;
    box-shadow: 0 0 3px var(--darken-weak);
}

.poster {
    width: 100%;
    height: 17rem;
    object-fit: cover;
    object-position: 50% 100%;
}

.title {
    width: 100%;
    display: flex;
    box-sizing: border-box;
    padding: .5rem 1rem;
    position: absolute;
    bottom: 0;
    background: var(--darken);
    font-size: 1rem;
    font-weight: bold;
    text-transform: capitalize;
    text-shadow: 0 0 3px var(--darken-strong);
}
</style>
