// src/App.tsx
import { CssBaseline, ThemeProvider, createTheme } from '@mui/material'
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'
import { useAuth } from './contexts/AuthContext'
import Layout from './components/Layout'
import Home from './pages/Home'
import Signup from './pages/Signup'
import LoginPage from './pages/Login'
import RegisterCharacter from './pages/RegisterCharacter'
import RegisterHomework from './pages/RegisterHomework'
import CharacterList from './pages/CharacterList'
import HomeworkList from './pages/HomeworkList'
import HomeworkEditPage from './pages/HomeworkEditPage'
import CharacterHomeworkSelect from './pages/CharacterHomeworkSelect'
import Dashboard from './pages/Dashboard'
import MePage from './pages/MePage'
import CharacterEditPage from './pages/CharacterEditPage'
import GuidePage from './pages/Guide'
import FriendListPage from './pages/FriendListPage'
import FriendRequestsPage from './pages/FriendRequestsPage'
import FriendCharacterDashboard from './pages/FriendCharacterDashboard'

const darkTheme = createTheme({
  palette: {
    mode: 'dark',
  },
})

function App() {
    const { isLoggedIn } = useAuth()

  return (
      <ThemeProvider theme={darkTheme}>
        <CssBaseline />
        <Router>
          <Layout key={isLoggedIn ? 'in' : 'out'}>
            <Routes>
              <Route path="/" element={<Home />} />
              <Route path="/signup" element={<Signup />} />
              <Route path="/login" element={<LoginPage />} />
              <Route path="/characters/register" element={<RegisterCharacter />} />
              <Route path="/characters" element={<CharacterList />} />
              <Route path="/homeworks" element={<HomeworkList />} />
              <Route path="/homeworks/register" element={<RegisterHomework />} />
              <Route path="/characters/:characterId/homeworks" element={<CharacterHomeworkSelect />} />
              <Route path="/dashboard" element={<Dashboard />} />
              <Route path="/signup" element={<Signup />} />
              <Route path="/me" element={<MePage />} />
              <Route path="/characters/:id/edit" element={<CharacterEditPage />} />
              <Route path="/homeworks/:id/edit" element={<HomeworkEditPage />} />
              <Route path="/guide" element={<GuidePage />} />
              <Route path="/friends" element={<FriendListPage />} />
              <Route path="/friends/:friend_id/characters" element={<FriendCharacterDashboard />} />
              <Route path="/friends/requests" element={<FriendRequestsPage />} />
            </Routes>
          </Layout>
        </Router>
      </ThemeProvider>
  )
}

export default App
