import { Navigate, Route, Routes } from 'react-router'
import { Toaster } from '@/components/ui/sonner'
import { AnalyticsPage } from '@/pages/AnalyticsPage'
import { BoardPage } from '@/pages/BoardPage'
import { CartablePage } from '@/pages/CartablePage'
import { LoginPage } from '@/pages/LoginPage'
import { MembersPage } from '@/pages/MembersPage'
import { OrgChartPage } from '@/pages/OrgChartPage'
import { PerformancePage } from '@/pages/PerformancePage'
import { ReviewsPage } from '@/pages/ReviewsPage'
import { SeatsPage } from '@/pages/SeatsPage'
import { SkillsPage } from '@/pages/SkillsPage'
import { StructurePage } from '@/pages/StructurePage'
import { useAuth } from '@/store/auth'

export default function App() {
  const token = useAuth((state) => state.token)

  return (
    <>
      <Routes>
        <Route path="/login" element={token ? <Navigate to="/" replace /> : <LoginPage />} />
        <Route path="/" element={token ? <BoardPage /> : <Navigate to="/login" replace />} />
        <Route path="/seats" element={token ? <SeatsPage /> : <Navigate to="/login" replace />} />
        <Route path="/reviews" element={token ? <ReviewsPage /> : <Navigate to="/login" replace />} />
        <Route path="/analytics" element={token ? <AnalyticsPage /> : <Navigate to="/login" replace />} />
        <Route path="/cartable" element={token ? <CartablePage /> : <Navigate to="/login" replace />} />
        <Route path="/members" element={token ? <MembersPage /> : <Navigate to="/login" replace />} />
        <Route path="/org" element={token ? <OrgChartPage /> : <Navigate to="/login" replace />} />
        <Route path="/structure" element={token ? <StructurePage /> : <Navigate to="/login" replace />} />
        <Route path="/skills" element={token ? <SkillsPage /> : <Navigate to="/login" replace />} />
        <Route path="/performance" element={token ? <PerformancePage /> : <Navigate to="/login" replace />} />
        <Route path="*" element={<Navigate to="/" replace />} />
      </Routes>
      <Toaster richColors position="top-right" />
    </>
  )
}
