import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom"
import AuthPage from "./components/AuthPage.jsx"
import MainApp from "./components/MainApp"
import SettingsPage from "./components/SettingsPage"
import "./index.css"

function ProtectedRoute({ children }) {
    const token = localStorage.getItem("token")
    if (!token) return <Navigate to="/auth" replace />
    return children
}

export default function App() {
    return (
        <BrowserRouter>
            <Routes>
                <Route path="/auth" element={<AuthPage />} />
                <Route path="/" element={
                    <ProtectedRoute>
                        <MainApp />
                    </ProtectedRoute>
                } />
                <Route path="/settings" element={
                    <ProtectedRoute>
                        <SettingsPage />
                    </ProtectedRoute>
                } />
            </Routes>
        </BrowserRouter>
    )
}
