<script setup lang="ts">
definePageMeta({
    layout: "explorer",
})

const route = useRoute();
const { data, status } = await useFetch(`/api/project/${route.params.projectId}/file/${encodeURIComponent(unifySlug(route.params.slug))}`);
</script>

<template>
    <Head>
        <Title v-if="data">{{ data.title }}</Title>
    </Head>
    <div class="flex-1 flex overflow-hidden">
        <template v-if="!!data && data.type == 'Markdown' && !!data.content">
            <div class="md:px-24 ps-8 my-1 whitespace-break-spaces">
                <ProseH1>{{ data.title }}</ProseH1>
                <Markdown v-model="data.content"></Markdown>
            </div>
            <CommentSide class="hidden" :comments="data.comments"></CommentSide>
        </template>
        <CanvasRenderer v-else-if="!!data && data.type == 'Canvas' && !!data.content" :canvas="JSON.parse(data.content)"></CanvasRenderer>
        <div v-else-if="!!data && data" class="h-100 w-100 flex flex-1 flex-col justify-center items-center">
            <div class="text-3xl font-extralight tracking-wide text-light-60 dark:text-dark-60">Impossible d'afficher (ou vide)</div>
            <div class="text-lg text-light-60 dark:text-dark-60">Cette page est actuellement vide ou impossible à traiter</div>
        </div>
        <div v-else class="h-100 w-100 flex flex-1 flex-col justify-center items-center">
            <div class="text-3xl font-extralight tracking-wide text-light-60 dark:text-dark-60">Introuvable</div>
            <div class="text-lg text-light-60 dark:text-dark-60">Cette page n'existe pas</div>
        </div>
    </div>
</template>