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

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

        <h3>Penetration</h3>

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

        <h3>Group</h3>

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

        <h3>Ethnicity</h3>

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

        <h3>Finish</h3>

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

        <h3>Misc</h3>

        <div 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: [] });
}

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

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

.tags {
    padding: 1rem;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
    grid-gap: .5rem;
}
</style>
