<template>
    <main>
        <Brush />
        <p>{{ globalData.magasin_explication }}</p>
        <div class="category">
            <div>
                <h3>Toiles</h3>
                <Projects :contents="toiles" />
            </div>
            <div>
                <h3>Impressions</h3>
                <Projects :contents="prints" />
            </div>
        </div>
    </main>
</template>

<script>
import Projects from '@/components/Projects.vue';
import Brush from '@/components/Brush.vue';

export default {
    async setup() {
        const toiles = ref([]);
        const prints = ref([]);

        const { data: toilesData } = useFetch('/api/items/toiles', { server: true });
        const { data: printsData } = useFetch('/api/items/prints', { server: true });

        onBeforeMount(async () => {
            if (toilesData.value) {
                toiles.value = toilesData.value.data;
            }
            if (printsData.value) {
                prints.value = printsData.value.data;
            }
        });

        let globalData = await useFetchGlobalData();
        globalData = globalData.globalData._object.$sglobalData;

        return {
            globalData,
            toiles,
            prints
        };
    },
    components: {
        Projects,
        Brush
    }
};
</script>

<style scoped lang="scss">
    h3:first-of-type {
        margin-top: 3rem;
    }
    h3 {
        text-transform: uppercase;
    }
    div > h3 + main {
        margin-top: 3vh;
    }

    @media screen and (min-width: 800px) {
        div > h3 + main {
            margin-top: 4vh;
        }
        .category {
            display: flex;
            > div {
                width: 50%;
            }
        }
    }
</style>