<template>
    <div class="h-screen overflow-hidden">
        <div class="flex h-full">
            <aside class="flex h-full w-64 flex-shrink-0 flex-col border-r border-neutral-200 bg-tertiary-500">
                <div class="h-[75px]">
                    <img src="/malio.png" alt="Logo" class="w-auto"/>
                </div>
                <nav class="flex-1 px-4 pb-6">
                    <template v-if="isAdmin">
                        <NuxtLink
                            to="/"
                            class="hidden flex items-center gap-3 px-4 pb-3 pt-6 text-md text-black hover:bg-tertiary-500 hover:text-primary-500 border-t border-secondary-500"
                            active-class="bg-tertiary-500 text-primary-500 font-bold"
                        >
                            Tableau de bord
                        </NuxtLink>
                        <NuxtLink
                            to="/calendar"
                            class="flex items-center gap-3 px-4 pb-3 pt-6 text-md text-black hover:bg-tertiary-500 hover:text-primary-500 border-t border-secondary-500"
                            :class="route.path.startsWith('/calendar')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                        >
                            Calendrier
                        </NuxtLink>
                    </template>
                    <NuxtLink
                        to="/hours"
                        class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                        :class="route.path.startsWith('/hours')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                    >
                        Heures
                    </NuxtLink>
                    <template v-if="isAdmin">
                        <NuxtLink
                            to="/employees"
                            class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                            :class="route.path.startsWith('/employees')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                        >
                            Employés
                        </NuxtLink>
                        <NuxtLink
                            to="/sites"
                            class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                            :class="route.path.startsWith('/sites')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                        >
                            Sites
                        </NuxtLink>
                        <NuxtLink
                            to="/absence-types"
                            class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                            :class="route.path.startsWith('/absence-types')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                        >
                            Types d'absence
                        </NuxtLink>
                        <NuxtLink
                            to="/users"
                            class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                            :class="route.path.startsWith('/users')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                        >
                            Utilisateurs
                        </NuxtLink>
                    </template>
                </nav>

                <div class="flex flex-col gap-2 items-center p-4">
                    <p class="font-bold">v{{ version }}</p>
                </div>
            </aside>

            <div class="h-full flex-1 overflow-hidden flex flex-col">
                <AppTopNav :user="auth.user" />
                <main class="flex-1 overflow-y-auto px-8 py-12">
                    <slot/>
                </main>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
const auth = useAuthStore()
const {version} = useAppVersion()
const isAdmin = computed(() => auth.user?.roles?.includes('ROLE_ADMIN') ?? false)
const route = useRoute()
</script>
