/**
 * Routes de l'app. AppLayout englobe toutes les pages "public" (sidebar visible).
 * /admin/login a son propre layout vide (pas de sidebar tant qu'on n'est pas loggé).
 */

import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import AppLayout from '@/layouts/AppLayout.vue'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: AppLayout,
    children: [
      { path: '', name: 'home', component: () => import('@/pages/HomePage.vue') },
      { path: 'dashboard', name: 'dashboard', component: () => import('@/pages/DashboardPage.vue') },
      { path: 'donut', name: 'donut', component: () => import('@/pages/DonutPage.vue') },
      { path: 'projects', name: 'projects', component: () => import('@/pages/ProjectsPage.vue') },
      { path: 'projects/new', name: 'project-new', component: () => import('@/pages/ProjectNewPage.vue') },
      { path: 'projects/:slug', name: 'project-detail', component: () => import('@/pages/ProjectDetailPage.vue'), props: true },
      { path: 'archives', name: 'archives', component: () => import('@/pages/ArchivesPage.vue') },
      { path: 'categories', name: 'categories', component: () => import('@/pages/CategoriesPage.vue') },
      { path: 'admin/login', name: 'admin-login', component: () => import('@/pages/AdminLoginPage.vue'), meta: { hideForAuthed: true } },
      { path: ':pathMatch(.*)*', name: 'not-found', component: () => import('@/pages/NotFoundPage.vue') },
    ],
  },
]

export const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior() {
    // Scroll en haut à chaque navigation (UX par défaut pour une SPA de contenu).
    return { top: 0 }
  },
})
