import { createRootRoute, createRoute, createRouter } from '@tanstack/react-router';
import { lazy } from 'react';

// Layout principal
const Layout = lazy(() => import('./components/layout/Layout'));

// Páginas
const DashboardPage = lazy(() => import('./pages/DashboardPage'));
const GamesPage = lazy(() => import('./pages/GamesPage'));
const GameDetailPage = lazy(() => import('./pages/GameDetailPage'));
const CreateGamePage = lazy(() => import('./pages/CreateGamePage'));
const ImportRomPage = lazy(() => import('./pages/ImportRomPage'));
const SettingsPage = lazy(() => import('./pages/SettingsPage'));
const PlatformsPage = lazy(() => import('./pages/PlatformsPage'));
const TagsPage = lazy(() => import('./pages/TagsPage'));
const ExportPage = lazy(() => import('./pages/ExportPage'));

// Ruta raíz
const rootRoute = createRootRoute({
  component: Layout,
});

// Rutas principales
const dashboardRoute = createRoute({
  path: '/',
  component: DashboardPage,
  getParentRoute: () => rootRoute,
});

const gamesRoute = createRoute({
  path: '/games',
  component: GamesPage,
  getParentRoute: () => rootRoute,
});

const gameDetailRoute = createRoute({
  path: '/games/$gameId',
  component: GameDetailPage,
  getParentRoute: () => rootRoute,
});

const createGameRoute = createRoute({
  path: '/games/create',
  component: CreateGamePage,
  getParentRoute: () => rootRoute,
});

const importRoute = createRoute({
  path: '/import',
  component: ImportRomPage,
  getParentRoute: () => rootRoute,
});

const settingsRoute = createRoute({
  path: '/settings',
  component: SettingsPage,
  getParentRoute: () => rootRoute,
});

const platformsRoute = createRoute({
  path: '/platforms',
  component: PlatformsPage,
  getParentRoute: () => rootRoute,
});

const tagsRoute = createRoute({
  path: '/tags',
  component: TagsPage,
  getParentRoute: () => rootRoute,
});

const exportRoute = createRoute({
  path: '/export',
  component: ExportPage,
  getParentRoute: () => rootRoute,
});

// Ruta de not found
const notFoundRoute = createRoute({
  path: '*',
  component: () => <div>Página no encontrada</div>,
  getParentRoute: () => rootRoute,
});

// Crear router
export const router = createRouter({
  routeTree: rootRoute.addChildren([
    dashboardRoute,
    gamesRoute,
    gameDetailRoute,
    createGameRoute,
    importRoute,
    settingsRoute,
    platformsRoute,
    tagsRoute,
    exportRoute,
    notFoundRoute,
  ]),
});
