import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { RouterProvider, createBrowserRouter, Navigate } from 'react-router';
import App from './App';
import List from './List';
import Login from './Login';
import './index.css';

const router = createBrowserRouter([
  {
    path: '/',
    element: <App />,
    children: [
      {
        index: true,
        element: <Navigate to="/list" />,
      },
      {
        path: 'list',
        element: (
          <App.RouteGuard>
            {(isLoggedIn) => (isLoggedIn ? <List /> : <Login />)}
          </App.RouteGuard>
        ),
      },
    ],
  },
]);

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <RouterProvider router={router} />
  </StrictMode>
);

