<template>
  <aside class="admin-sidebar">
    <div class="sidebar-header">
      <NuxtLink to="/admin" class="flex items-center gap-2 font-display text-lg font-bold">
        <div class="i-lucide-settings h-5 w-5 text-primary" />
        <span class="text-gradient">Admin</span>
      </NuxtLink>
    </div>

    <nav class="sidebar-nav">
      <p class="sidebar-section">Contenu</p>
      <NuxtLink to="/admin" class="sidebar-link" exact-active-class="sidebar-link--active">
        <div class="i-lucide-layout-dashboard h-4 w-4" />
        Dashboard
      </NuxtLink>
      <NuxtLink to="/admin/site" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-globe h-4 w-4" />
        Site
      </NuxtLink>
      <NuxtLink to="/admin/messages" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-message-square h-4 w-4" />
        Messages
      </NuxtLink>

      <p class="sidebar-section">Pages</p>
      <NuxtLink to="/admin/pages" class="sidebar-link" exact-active-class="sidebar-link--active">
        <div class="i-lucide-file-text h-4 w-4" />
        Toutes les pages
      </NuxtLink>
      <NuxtLink to="/admin/pages/home" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-home h-4 w-4" />
        Accueil
      </NuxtLink>
      <NuxtLink to="/admin/pages/numerique" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-monitor h-4 w-4" />
        Numérique
      </NuxtLink>
      <NuxtLink to="/admin/pages/economique" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-coins h-4 w-4" />
        Économique
      </NuxtLink>
      <NuxtLink to="/admin/pages/citoyenne" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-landmark h-4 w-4" />
        Citoyenne
      </NuxtLink>
      <NuxtLink to="/admin/pages/en-musique" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-headphones h-4 w-4" />
        En musique
      </NuxtLink>
      <NuxtLink to="/admin/pages/gratewizard" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-sparkles h-4 w-4" />
        grateWizard
      </NuxtLink>

      <p class="sidebar-section">Livre</p>
      <NuxtLink to="/admin/book" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-list h-4 w-4" />
        Chapitres
      </NuxtLink>
      <NuxtLink to="/admin/songs" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-music h-4 w-4" />
        Chansons
      </NuxtLink>

      <p class="sidebar-section">Médias</p>
      <NuxtLink to="/admin/media" class="sidebar-link" active-class="sidebar-link--active">
        <div class="i-lucide-image h-4 w-4" />
        Navigateur
      </NuxtLink>
    </nav>

    <div class="sidebar-footer">
      <NuxtLink to="/" class="sidebar-link" target="_blank">
        <div class="i-lucide-external-link h-4 w-4" />
        Voir le site
      </NuxtLink>
      <button class="sidebar-link w-full" @click="logout">
        <div class="i-lucide-log-out h-4 w-4" />
        Déconnexion
      </button>
    </div>
  </aside>
</template>

<script setup lang="ts">
async function logout() {
  await $fetch('/api/admin/auth/logout', { method: 'POST' })
  navigateTo('/admin/login')
}
</script>

<style scoped>
.admin-sidebar {
  background: hsl(var(--color-bg));
  border-right: 1px solid hsl(var(--color-surface-light));
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: sticky;
  top: 0;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid hsl(var(--color-surface-light));
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem;
  overflow-y: auto;
}

.sidebar-section {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: hsl(var(--color-text-muted));
  padding: 1rem 0.75rem 0.375rem;
  margin: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  color: hsl(var(--color-text-muted));
  text-decoration: none;
  transition: all 0.2s;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
}

.sidebar-link:hover {
  background: hsl(var(--color-surface));
  color: white;
}

.sidebar-link--active {
  background: hsl(var(--color-primary) / 0.12);
  color: hsl(var(--color-primary));
}

.sidebar-footer {
  padding: 0.5rem;
  border-top: 1px solid hsl(var(--color-surface-light));
}

@media (max-width: 768px) {
  .admin-sidebar {
    display: none;
  }
}
</style>
