import { type FC } from "react";
import { createBrowserRouter, RouterProvider } from "react-router";

import IndexPage from "./pages/Index";
import LoginPage from "./pages/Login";
import RegisterPage from "./pages/Register";
import AuthorizePage from "./pages/Authorize";
import AuthenticatePage from "./pages/Authenticate";
import AuthLayout from "./layout/AuthLayout";
import DashboardLayout from "./layout/DashboardLayout";
import PersonalInfoPage from "./pages/PersonalInfo";
import ApiServicesPage from "./pages/Admin/ApiServices";
import AdminLayout from "./layout/AdminLayout";
import ApiServiceCreatePage from "./pages/Admin/ApiServices/Create";
import ViewApiServicePage from "./pages/Admin/ApiServices/View";
import NotAllowedPage from "./pages/NotAllowed";
import NotFoundPage from "./pages/NotFound";
import ApiServiceEditPage from "./pages/Admin/ApiServices/Update";
import AdminUsersPage from "./pages/Admin/Users";
import AdminViewUserPage from "./pages/Admin/Users/View";
import AdminCreateUserPage from "./pages/Admin/Users/Create";

const router = createBrowserRouter([
  {
    path: "/",
    element: <AuthLayout />,
    children: [
      {
        path: "/",
        element: <DashboardLayout />,
        children: [
          {
            index: true,
            element: <IndexPage />,
          },
          {
            path: "personal-info",
            element: <PersonalInfoPage />,
          },
          {
            path: "admin",
            element: <AdminLayout />,
            children: [
              {
                path: "api-services",
                children: [
                  { index: true, element: <ApiServicesPage /> },
                  { path: "create", element: <ApiServiceCreatePage /> },
                  {
                    path: "view/:serviceId",
                    element: <ViewApiServicePage />,
                  },
                  {
                    path: "edit/:serviceId",
                    element: <ApiServiceEditPage />,
                  },
                ],
              },
              {
                path: "users",
                children: [
                  { index: true, element: <AdminUsersPage /> },
                  { path: "create", element: <AdminCreateUserPage /> },
                  {
                    path: "view/:userId",
                    element: <AdminViewUserPage />,
                  },
                  // {
                  //   path: "edit/:serviceId",
                  //   element: <ApiServiceEditPage />,
                  // },
                ],
              },
            ],
          },
        ],
      },
    ],
  },
  {
    path: "/auth",
    element: <AuthLayout />,
    children: [
      { index: true, element: <AuthorizePage /> },
      { path: "login", element: <LoginPage /> },
      { path: "register", element: <RegisterPage /> },
      { path: "authenticate", element: <AuthenticatePage /> },
    ],
  },
  {
    path: "/not-allowed",
    element: <NotAllowedPage />,
  },
  {
    path: "*",
    element: <NotFoundPage />,
  },
]);

const App: FC = () => {
  return <RouterProvider router={router} />;
};

export default App;
