// AppRoutes.jsx
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 ResetPasswordPage from "../pages/authentication/ResetPasswordPage";

// 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/support/ErrorPage";
import LegalInfoCard from "../pages/TermsAndConditions/LegalInfoCard";

// Protected Route Wrapper
import ProtectedRoute from "./ProtectedRoute";

const router = createBrowserRouter(
  [
    {
      element: <AuthLayout />,
      children: [
        { path: "/auth/login", element: <LoginPage /> },
        { path: "/auth/reqest/demo", element: <RegisterPage /> },
        { path: "/auth/forgot-password", element: <ForgotPasswordPage /> },
        { path: "/reset-password", element: <ResetPasswordPage /> },
        { path: "/legal-info", element: <LegalInfoCard /> },
      ],
    },
    {
      element: <ProtectedRoute />,
      children: [
        {
          element: <HomeLayout />,
          children: [
            { path: "/", element: <Dashboard /> },
            { path: "/dashboard", element: <Dashboard /> },
            { path: "/projects", element: <ProjectList /> },
            { path: "/projects/:projectId", 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: "/inventory", element: <Inventory /> },
            { path: "/activities/attendance", element: <AttendancePage /> },
            { path: "/activities/records", element: <DailyTask /> },
            { path: "/activities/task", element: <TaskPlannng /> },
            { path: "/activities/reports", element: <Reports /> },
            { path: "/activities/gallary", element: <ImageGallary /> },
            { path: "/masters", element: <MasterPage /> },
            { path: "/help/support", element: <Support /> },
            { path: "/help/docs", element: <Documentation /> },
            { path: "/help/connect", element: <Connect /> },
          ],
        },
      ],
    },
    {
      path: "*",
      element: <ErrorPage />,
    },
  ],
  {
    // ✅ Enables the v7 splat path resolution behavior
    future: {
      v7_relativeSplatPath: true,
      v7_startTransition: true,
    },
  }
);

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

export default AppRoutes;
