<template>
	<div class="tags">
		<div
			v-for="(tags, category) in categories"
			:key="category"
			class="category"
		>
			<h3 class="heading">{{ category }}</h3>

			<div
				:key="sfw"
				v-lazy-container
				class="tiles"
			>
				<Tag
					v-for="tag in tags"
					:key="`tag-${tag.id}`"
					:tag="tag"
					:lazy="true"
				/>
			</div>
		</div>
	</div>
</template>

<script>
import Tag from './tile.vue';

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

async function mounted() {
	const tagSlugsByCategory = {
		popular: [
			'anal',
			'lesbian',
			'interracial',
			'mff',
			'mfm',
			'teen',
			'milf',
			'blowjob',
			'orgy',
			'gangbang',
			'dp',
			'facial',
			'creampie',
			'squirting',
		],
		ethnicity: [
			'asian',
			'ebony',
			'latina',
			'caucasian',
		],
		appearance: [
			'natural-boobs',
			'fake-boobs',
			'blonde',
			'brunette',
			'redhead',
			'tattoos',
			'piercings',
		],
		oral: [
			'blowjob',
			'deepthroat',
			'facefucking',
			'double-blowjob',
			'blowbang',
			'pussy-eating',
			'ass-eating',
			'atm',
		],
		extreme: [
			'airtight',
			'dap',
			'dvp',
			'da-tp',
			'dv-tp',
			'tap',
		],
		cumshot: [
			'facial',
			'bukkake',
			'creampie',
			'anal-creampie',
			'cum-in-mouth',
			'oral-creampie',
			'cum-on-butt',
		],
		roleplay: [
			'family',
			'parody',
			'schoolgirl',
			'nurse',
			'maid',
		],
		fetish: [
			'bdsm',
			'bondage',
			'femdom',
		],
		toys: [
			'double-dildo',
			'double-dildo-blowjob',
		],
		misc: [
			'gaping',
			'squirting',
			'oil',
		],
	};

	const tags = await this.$store.dispatch('fetchTags', {
		slugs: Object.values(tagSlugsByCategory).flat(),
	});

	const tagsBySlug = tags.reduce((acc, tag) => ({ ...acc, [tag.slug]: tag }), {});

	this.categories = Object.entries(tagSlugsByCategory).reduce((acc, [category, tagSlugs]) => ({
		...acc,
		[category]: tagSlugs.map(tagSlug => tagsBySlug[tagSlug]),
	}), {});

	this.pageTitle = 'Tags';
}

export default {
	components: {
		Tag,
	},
	data() {
		return {
			categories: {},
			pageTitle: null,
		};
	},
	computed: {
		sfw,
	},
	mounted,
};
</script>

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

.tags {
    padding: 1rem;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(23rem, .33fr));
    grid-gap: 1rem;
    margin: 0 0 1.5rem 0;
}

.heading {
	display: inline-block;
	color: var(--primary);
	padding: 0 .5rem;
	margin: .5rem 0 1rem 0;
    font-size: 1.2rem;
    text-transform: capitalize;
}

@media(max-width: $breakpoint3) {
    .tiles {
        grid-template-columns: repeat(auto-fill, minmax(20rem, .5fr));
    }
}

@media(max-width: $breakpoint) {
    .tiles {
        grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
		grid-gap: .5rem;
    }
}

@media(max-width: $breakpoint0) {
    .tiles {
        grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
    }
}
</style>
