import { createBrowserRouter, Navigate } from "react-router-dom";
import Login from "../pages/Login";
import ProtectedRoute from "./ProtectedRoute";
import CommonLayout from "../layouts/CommonLayout";
import Reserve from "../pages/user/Reserve";
import MyReservation from "../pages/user/MyReservation";
import UserDetail from "../pages/user/UserDetail";
import LeaderApproval from "../pages/leader/Approval";

const router = createBrowserRouter([
  {
    path: "/",
    element: <Navigate to="/login" replace />,
  },
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "/",
    element: <CommonLayout />,
    children: [
      {
        path: "user",
        element: <ProtectedRoute allowedRoles={["USER"]} />,
        children: [
          {
            path: "reserve",
            element: <Reserve />,
          },
          {
            path: "my-reservation",
            element: <MyReservation />,
          },
          {
            path: "userdetail",
            element: <UserDetail />,
          },
        ],
      },
      {
        path: "leader",
        element: <ProtectedRoute allowedRoles={["LEADER"]} />,
        children: [
          {
            path: "approval",
            element: <LeaderApproval />,
          },
        ],
      },
    ],
  },
]);

export default router;
