<template>
  <div>
    <h1 class="font-display text-2xl font-bold text-white mb-6">Chapitres</h1>

    <div class="flex flex-col gap-2">
      <NuxtLink
        v-for="chapter in chapters"
        :key="chapter.slug"
        :to="`/admin/book/${chapter.slug}`"
        class="chapter-item"
      >
        <span class="chapter-order">{{ String(chapter.order ?? 0).padStart(2, '0') }}</span>
        <span class="chapter-title">{{ chapter.title }}</span>
        <div class="i-lucide-chevron-right h-4 w-4 text-white/20" />
      </NuxtLink>
    </div>
  </div>
</template>

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

const { data: chapters } = await useFetch('/api/admin/chapters')
</script>

<style scoped>
.chapter-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid hsl(20 8% 14%);
  border-radius: 0.5rem;
  text-decoration: none;
  transition: all 0.2s;
}

.chapter-item:hover {
  border-color: hsl(12 76% 48% / 0.3);
  background: hsl(20 8% 6%);
}

.chapter-order {
  font-family: var(--font-mono, monospace);
  font-size: 0.85rem;
  color: hsl(12 76% 48% / 0.5);
  font-weight: 600;
  width: 1.75rem;
}

.chapter-title {
  flex: 1;
  color: white;
  font-weight: 500;
}
</style>
