<template>
	<router-link
		:to="{ name: 'tag', params: { tagSlug: tag.slug, range: 'latest' } }"
		:title="tag.name"
		class="tile"
	>
		<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>

		<span class="title">{{ tag.name }}</span>
	</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);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    box-sizing: border-box;
    position: relative;
	text-decoration: none;
    box-shadow: 0 0 3px var(--darken-weak);
	overflow: hidden;
}

.poster {
    width: 100%;
	height: 100%;
    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);
	overflow: hidden;
	white-space: nowrap;
    font-size: 1rem;
    font-weight: bold;
    text-transform: capitalize;
    text-shadow: 0 0 3px var(--darken-strong);
	text-overflow: ellipsis;
}

@media(max-width: $breakpoint) {
	.tile {
		position: initial;
	}

	.title {
		position: initial;
		color: var(--text);
		background: var(--background);
		text-shadow: none;
	}
}
</style>
