<template>
    <div v-if="status === 'pending'" class="flex">
        <Head>
            <Title>d[any] - Chargement</Title>
        </Head>
        <Loading />
    </div>
    <div class="flex flex-1 justify-start items-start" v-else-if="overview">
        <Head>
            <Title>d[any] - {{ overview.title }}</Title>
        </Head>
        <Markdown v-if="overview.type === 'markdown'" :overview="overview" />
        <Canvas v-else-if="overview.type === 'canvas'" :overview="overview" />
        <ProseH2 v-else class="flex-1 text-center">Impossible d'afficher le contenu demandé</ProseH2>
    </div>
    <div v-else-if="status === 'error'">
        <Head>
            <Title>d[any] - Erreur</Title>
        </Head>
        <span>{{ error?.message }}</span>
    </div>
    <div v-else>
        <Head>
            <Title>d[any] - Erreur</Title>
        </Head>
        <div><ProseH2>Impossible d'afficher le contenu demandé</ProseH2></div>
    </div>
</template>

<script setup lang="ts">
const route = useRouter().currentRoute;
const path = computed(() => Array.isArray(route.value.params.path) ? route.value.params.path[0] : route.value.params.path);

const { data: overview, status, error } = await useFetch(`/api/file/overview/${encodeURIComponent(path.value)}`, { watch: [route, path], });
</script>