import React from "react";
import { createBrowserRouter, RouterProvider, Outlet } from "react-router-dom";

// Layouts
import AuthLayout from "../layouts/AuthLayout";
import HomeLayout from "../layouts/HomeLayout";

// Authentication Pages
import LoginPage from "../pages/authentication/LoginPage";
import RegisterPage from "../pages/authentication/RegisterPage";
import ForgotPasswordPage from "../pages/authentication/ForgotPasswordPage";
import ChangePasswordPage from "../pages/authentication/ChangePassword";

// Home & Protected Pages
import Dashboard from "../components/Dashboard/Dashboard";
import ProjectList from "../pages/project/ProjectList";
import ProjectDetails from "../pages/project/ProjectDetails";
import ManageProject from "../components/Project/ManageProject";
import EmployeeList from "../pages/employee/EmployeeList";
// import ManageEmp from "../pages/employee/ManageEmp";
import EmployeeProfile from "../pages/employee/EmployeeProfile";
import Inventory from "../pages/project/Inventory";
import AttendancePage from "../pages/Activities/AttendancePage";
import DailyTask from "../pages/Activities/DailyTask";
import TaskPlannng from "../pages/Activities/TaskPlannng";
import Reports from "../pages/reports/Reports";
import ImageGallary from "../pages/Gallary/ImageGallary";
import MasterPage from "../pages/master/MasterPage";
import Support from "../pages/support/Support";
import Documentation from "../pages/support/Documentation";
import Connect from "../pages/support/Connect";
import ErrorPage from "../pages/ErrorPage";
import LegalInfoCard from "../pages/TermsAndConditions/LegalInfoCard";

// Protected Route Wrapper
import ProtectedRoute from "./ProtectedRoute";
import LoginWithOtp from "../pages/authentication/LoginWithOtp";
import ExpensePage from "../pages/Expense/ExpensePage";
import TenantDetails from "../pages/Tenant/TenantDetails";
import SelfTenantDetails from "../pages/Tenant/SelfTenantDetails";
import SuperTenantDetails from "../pages/Tenant/SuperTenantDetails";
import DirectoryPage from "../pages/Directory/DirectoryPage";
import RootRedirect from "./RootRedirect";
import MainLogin from "../pages/authentication/MainLogin";
import MainLoginWithOTPPage from "../pages/authentication/MainLoginWithOTPPage";
import MainRegisterPage from "../pages/authentication/MainRegisterPage";
import MainForgetPage from "../pages/authentication/MainForgetPage";
import MainResetPasswordPage from "../pages/authentication/MainResetPasswordPage";
import TenantPage from "../pages/Tenant/TenantPage";
import { Navigate } from "react-router-dom";
import CreateTenant from "../pages/Tenant/CreateTenant";
import LandingPage from "../pages/Home/LandingPage";
const router = createBrowserRouter(
  [
    {
      path: "/",
      element: <LandingPage />,
    },
    {
      element: <AuthLayout />,
      children: [
        { path: "/auth/login", element: <MainLogin /> },
        { path: "/auth/login-otp", element: <MainLoginWithOTPPage /> },
        { path: "/auth/reqest/demo", element: <MainRegisterPage /> },
        { path: "/auth/forgot-password", element: <MainForgetPage /> },
        { path: "/reset-password", element: <MainResetPasswordPage /> },
        { path: "/legal-info", element: <LegalInfoCard /> },
        { path: "/auth/changepassword", element: <ChangePasswordPage /> },
      ],
    },
    {
      element: <ProtectedRoute />,
      errorElement: <ErrorPage />,
      children: [
        {
          element: <HomeLayout />,
          children: [
            { path: "/dashboard", element: <Dashboard /> },
            { path: "/projects", element: <ProjectList /> },
            { path: "/projects/details", element: <ProjectDetails /> },
            { path: "/project/manage/:projectId", element: <ManageProject /> },
            { path: "/employees", element: <EmployeeList /> },
            { path: "/employee/:employeeId", element: <EmployeeProfile /> },
            // { path: "/employee/manage", element: <ManageEmp /> },
            // {path: "/employee/manage/:employeeId", element: <ManageEmp />},
            { path: "/directory", element: <DirectoryPage /> },
            { path: "/inventory", element: <Inventory /> },
            { path: "/activities/attendance", element: <AttendancePage /> },
            { path: "/activities/records/:projectId?", element: <DailyTask /> },
            { path: "/activities/task", element: <TaskPlannng /> },
            { path: "/activities/reports", element: <Reports /> },
            { path: "/gallary", element: <ImageGallary /> },
            { path: "/expenses", element: <ExpensePage /> },
            { path: "/masters", element: <MasterPage /> },
            { path: "/tenants", element: <TenantPage /> },
            { path: "/tenants/new-tenant", element: <CreateTenant /> },
            { path: "/tenant/:tenantId", element: <SuperTenantDetails /> },
            { path: "/tenant/self", element: <SelfTenantDetails /> },
            { path: "/help/support", element: <Support /> },
            { path: "/help/docs", element: <Documentation /> },
            { path: "/help/connect", element: <Connect /> },
          ],
        },
      ],
    },
    {
      path: "*",
      element: <ErrorPage />,
    },
  ],
  {
    future: {
      v7_relativeSplatPath: true,
      v7_startTransition: true,
      v7_fetcherPersist: true,
      v7_normalizeFormMethod: true,
      v7_partialHydration: true,
      v7_skipActionErrorRevalidation: true,
    },
  }
);

const AppRoutes = () => {
  return <RouterProvider router={router} />;
};

export default AppRoutes;
