import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import { AuthProvider } from "./auth/auth-provider";
import { HomePage } from "./auth/home-page";
import { LoginPage } from "./auth/login-page";
import { RequireAuth } from "./auth/require-auth";
import { RequireEmployee } from "./auth/require-employee";
import { AppLayout } from "./layouts/app-layout";
import { OrderPage } from "./orders/order-page";
import { OrdersPage } from "./orders/orders-page";

export default function App() {
  return (
    <BrowserRouter>
      <AuthProvider>
        <Routes>
          <Route element={<AppLayout />}>
            <Route path="login" element={<LoginPage />} />
            <Route element={<RequireAuth />}>
              <Route index element={<HomePage />} />
              <Route element={<RequireEmployee />}>
                <Route path="orders" element={<OrdersPage />} />
                <Route path="orders/:orderId" element={<OrderPage />} />
              </Route>
            </Route>
            <Route path="*" element={<Navigate replace to="/" />} />
          </Route>
        </Routes>
      </AuthProvider>
    </BrowserRouter>
  );
}
