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

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 />,
          },
        ],
      },
      {
        element: <ProtectedRoute allowedRoles={["LEADER", "DEVICE_ADMIN"]} />,
        children: [
          {
            path: "approval",
            element: <Approval />,
          },
          {
            path: "my-approval",
            element: <MyApproval />,
          },
        ],
      },

      {
        path: "userdetail",
        element: <UserDetail />,
      },
    ],
  },
]);

export default router;
