<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="/calendar"
                            class="flex items-center gap-2 pb-2 pt-3 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'
                            : ''"
                        >
                            <Icon name="mdi:calendar-blank" size="24"/>
                            <p>Calendrier</p>
                        </NuxtLink>
                    </template>
                    <NuxtLink
                        v-if="isAdmin || !isDriver"
                        to="/hours"
                        class="flex items-center gap-2 py-2 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' : '',
                            !isAdmin ? 'border-t border-secondary-500 pt-3' : ''
                        ]"
                    >
                        <Icon name="mdi:clock-time-four-outline" size="24"/>
                        <p>Heures</p>
                    </NuxtLink>
                    <NuxtLink
                        v-if="isAdmin || isDriver"
                        to="/driver-hours"
                        class="flex items-center gap-2 py-2 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                        :class="[
                            route.path.startsWith('/driver-hours') ? 'bg-tertiary-500 text-primary-500 font-bold' : '',
                            !isAdmin && isDriver ? 'border-t border-secondary-500 pt-3' : ''
                        ]"
                    >
                        <Icon name="mdi:truck-outline" size="24"/>
                        <p>Heures Conducteurs</p>
                    </NuxtLink>
                    <template v-if="isAdmin">
                        <NuxtLink
                            to="/employees"
                            class="flex items-center gap-2 py-2 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'
                            : ''"
                        >
                            <Icon name="mdi:account-group-outline" size="24"/>
                            <p>Employés</p>
                        </NuxtLink>
                        <NuxtLink
                            v-if="hasLeaveRecapAccess"
                            to="/leave-recap"
                            class="flex items-center gap-2 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                            :class="route.path.startsWith('/leave-recap')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                        >
                            <Icon name="mdi:beach" size="24"/>
                            <p>Récap. congés</p>
                        </NuxtLink>
                        <NuxtLink
                            to="/sites"
                            class="flex items-center gap-2 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'
                            : ''"
                        >
                            <Icon name="mdi:business" size="24"/>
                            <p>Sites</p>
                        </NuxtLink>
                        <NuxtLink
                            to="/absence-types"
                            class="flex items-center gap-2 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'
                            : ''"
                        >
                            <Icon name="mdi:umbrella-beach-outline" size="24"/>
                            <p>Types de statut</p>
                        </NuxtLink>
                        <NuxtLink
                            to="/users"
                            class="flex items-center gap-3 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'
                            : ''"
                        >
                            <Icon name="mdi:account-outline" size="24"/>
                            <p>Utilisateurs</p>
                        </NuxtLink>
                    </template>
                    <NuxtLink
                        v-if="hasLeaveRecapAccess && !isAdmin"
                        to="/leave-recap"
                        class="flex items-center gap-2 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500 pt-3"
                        :class="route.path.startsWith('/leave-recap') ? 'bg-tertiary-500 text-primary-500 font-bold' : ''"
                    >
                        <Icon name="mdi:beach" size="24"/>
                        <p>Récap. congés</p>
                    </NuxtLink>
                    <NuxtLink
                        v-if="isSuperAdmin"
                        to="/audit-logs"
                        class="flex items-center gap-2 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                        :class="route.path.startsWith('/audit-logs')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                    >
                        <Icon name="mdi:clipboard-text-clock-outline" size="24"/>
                        <p>Journal</p>
                    </NuxtLink>
                    <NuxtLink
                        to="/documentation"
                        class="flex items-center gap-2 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
                        :class="route.path.startsWith('/documentation')
                            ? 'bg-tertiary-500 text-primary-500 font-bold'
                            : ''"
                    >
                        <Icon name="mdi:book-open-page-variant-outline" size="24"/>
                        <p>Documentation</p>
                    </NuxtLink>
                </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 isSuperAdmin = computed(() => auth.user?.roles?.includes('ROLE_SUPER_ADMIN') ?? false)
const isDriver = computed(() => auth.user?.isDriver ?? false)
const hasLeaveRecapAccess = computed(() => auth.user?.hasLeaveRecapAccess ?? false)
const route = useRoute()
</script>
