import {
  RouterProvider,
  createBrowserRouter,
  Navigate,
} from 'react-router-dom';
import Chat from './pages/Chat.tsx';
import Login from './pages/Login.tsx';
import Signup from './pages/Signup.tsx';
import Settings from './pages/Settings.tsx';
import Lost from './pages/404.tsx';
import { AuthProvider } from './utils/AuthProvider.tsx';
import ProtectedRoutes from './utils/ProtectedRoutes.tsx';
import { ChatProvider } from '@/context/chat/ChatProvider.tsx';
import PublicRoute from '@/utils/PublicRoute.tsx';

const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to="/chat" replace />,
  },
  {
    element: <ProtectedRoutes />,
    children: [
      {
        path: '/chat',
        element: (
          <ChatProvider>
            <Chat />
          </ChatProvider>
        ),
      },
      {
        path: '/settings',
        element: <Settings />,
      },
    ],
  },
  {
    element: <PublicRoute />,
    children: [
      {
        path: '/login',
        element: <Login />,
      },
      {
        path: '/signup',
        element: <Signup />,
      },
    ],
  },
  {
    path: '*',
    element: <Lost />,
  },
]);

function App() {
  return (
    <AuthProvider>
      <RouterProvider router={router} />
    </AuthProvider>
  );
}

export default App;
