<template>
    <div class="content">
        <FilterBar
            :filter="filter"
            @set-filter="setFilter"
        />

        <div class="content-inner">
            <ul class="scenes nolist">
                <li
                    v-for="release in releases"
                    :key="release.id"
                    class="scene"
                >
                    <ReleaseTile :release="release" />
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import FilterBar from './filter.vue';
import ReleaseTile from '../tile/release.vue';

async function fetchReleases() {
    this.releases = await this.$store.dispatch('fetchReleases', {
        filter: this.filter,
    });
}

async function setFilter(filter) {
    this.filter = filter;
    localStorage.setItem('filter', this.filter);

    await this.fetchReleases();
}

async function mounted() {
    this.pageTitle = '';

    await this.fetchReleases();
}

export default {
    components: {
        FilterBar,
        ReleaseTile,
    },
    data() {
        const storedFilter = localStorage.getItem('filter');

        return {
            filter: storedFilter ? storedFilter.split(',') : ['gay', 'transsexual'],
            releases: [],
            networks: [],
            pageTitle: null,
        };
    },
    mounted,
    methods: {
        fetchReleases,
        setFilter,
    },
};
</script>
