<template>
    <div class="tags">
        <h3 class="heading">Oral</h3>

        <div class="tiles">
            <Tag
                v-for="tag in tags.oral"
                :key="`tag-${tag.id}`"
                :tag="tag"
            />
        </div>

        <h3 class="heading">Penetration</h3>

        <div class="tiles">
            <Tag
                v-for="tag in tags.penetration"
                :key="`tag-${tag.id}`"
                :tag="tag"
            />
        </div>

        <h3 class="heading">Group</h3>

        <div class="tiles">
            <Tag
                v-for="tag in tags.group"
                :key="`tag-${tag.id}`"
                :tag="tag"
            />
        </div>

        <h3 class="heading">Ethnicity</h3>

        <div class="tiles">
            <Tag
                v-for="tag in tags.ethnicity"
                :key="`tag-${tag.id}`"
                :tag="tag"
            />
        </div>

        <h3 class="heading">Finish</h3>

        <div class="tiles">
            <Tag
                v-for="tag in tags.finish"
                :key="`tag-${tag.id}`"
                :tag="tag"
            />
        </div>

        <h3 class="heading">Misc</h3>

        <div
            v-if="tags.misc"
            class="tiles"
        >
            <Tag
                v-for="tag in tags.misc.concat(tags.body)"
                :key="`tag-${tag.id}`"
                :tag="tag"
            />
        </div>
    </div>
</template>

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

async function mounted() {
    const tags = await this.$store.dispatch('fetchTags', {
        slugs: [
            'airtight',
            'anal',
            'anal-creampie',
            'asian',
            'ass-eating',
            'ass-to-mouth',
            'bdsm',
            'blowbang',
            'blowjob',
            'bukkake',
            'caucasian',
            'creampie',
            'da-tp',
            'deepthroat',
            'double-anal',
            'double-blowjob',
            'double-penetration',
            'double-vaginal',
            'dv-tp',
            'ebony',
            'facefucking',
            'facial',
            'gangbang',
            'gaping',
            'interracial',
            'latina',
            'mff',
            'mfm',
            'oral-creampie',
            'orgy',
            'pussy-eating',
            'swallowing',
            'tattoo',
            'trainbang',
            'triple-anal',
        ],
    });

    this.tags = tags.reduce((acc, tag) => {
        if (!tag.group) {
            return { ...acc, misc: [...acc.misc, tag] };
        }

        if (acc[tag.group.slug]) {
            return { ...acc, [tag.group.slug]: [...acc[tag.group.slug], tag] };
        }

        return { ...acc, [tag.group.slug]: [tag] };
    }, { misc: [] });

    this.pageTitle = 'Tags';
}

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

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

.tags {
    padding: 1rem;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(20rem, .25fr));
    grid-gap: .5rem;
    margin: 0 0 1.5rem 0;
}

.heading {
    font-size: 1.3rem;
}

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

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