import { Navigate, Route, Routes } from 'react-router-dom'
import { useAppSelector } from './store/hooks'
import LoginPage from './pages/usr/LoginPage'
import UserListPage from './pages/usr/UserListPage'

function PrivateRoute({ children }: { children: React.ReactNode }) {
  const accessToken = useAppSelector(s => s.auth.accessToken)
  return accessToken ? <>{children}</> : <Navigate to="/login" replace />
}

export default function App() {
  return (
    <Routes>
      <Route path="/login" element={<LoginPage />} />
      <Route path="/" element={<PrivateRoute><div>主页（待实现）</div></PrivateRoute>} />
      <Route path="/usr/users" element={<PrivateRoute><UserListPage /></PrivateRoute>} />
      <Route path="*" element={<Navigate to="/" replace />} />
    </Routes>
  )
}
