import React from 'react'
import { Routes, Route, Navigate } from 'react-router-dom'
import { RequireAuth, RequireAdmin, GuestOnly } from '@/components/layout/Guards'
import { LoginPage, RegisterPage, PendingPage } from '@/pages/auth/AuthPages'
import { DeckListPage } from '@/pages/decks/DeckListPage'
import { DeckViewPage } from '@/pages/decks/DeckViewPage'
import { BuildDeckPage } from '@/pages/decks/BuildDeckPage'
import { CollectionPage } from '@/pages/collection/CollectionPage'
import { AdminPage } from '@/pages/admin/AdminPage'
import { ProfilePage } from '@/pages/ProfilePage'

export function App() {
  return (
    <Routes>
      {/* Public / guest routes */}
      <Route element={<GuestOnly />}>
        <Route path="/login" element={<LoginPage />} />
        <Route path="/register" element={<RegisterPage />} />
      </Route>

      {/* Pending holding page — accessible when logged in but pending */}
      <Route path="/pending" element={<PendingPage />} />

      {/* Protected routes */}
      <Route element={<RequireAuth />}>
        <Route path="/decks" element={<DeckListPage />} />
        <Route path="/decks/:id" element={<DeckViewPage />} />
        <Route path="/build" element={<BuildDeckPage />} />
        <Route path="/collection" element={<CollectionPage />} />
        <Route path="/profile" element={<ProfilePage />} />

        {/* Admin-only */}
        <Route element={<RequireAdmin />}>
          <Route path="/admin" element={<AdminPage />} />
        </Route>
      </Route>

      {/* Default redirect */}
      <Route path="/" element={<Navigate to="/decks" replace />} />
      <Route path="*" element={<Navigate to="/decks" replace />} />
    </Routes>
  )
}
