import type { ReactNode } from 'react';
import type { RouteObject } from 'react-router-dom';
import { APP_ROUTE_PATHS } from '@/shared/constants/routes';
import {
  CampusAttendancePage,
  ClassroomSupportPage,
  ClassroomTimerPage,
  CommunityPartnershipsPage,
  DashboardPage,
  DirectorDashboardPage,
  EmotionalIntelligencePage,
  EsaFundingPage,
  FramePage,
  HandbookPoliciesPage,
  InternalAlertsPage,
  ParentCommunicationPage,
  QbsSafetyPage,
  SafetyProtocolsPage,
  SignLanguagePage,
  VocationalOpportunitiesPage,
  WalkthroughPage,
  ZonesOfRegulationPage,
} from '@/app/lazyModulePages';
import { ModuleRouteGuard } from '@/app/ModuleRouteGuard';
import { AuthGuard } from '@/app/AuthGuard';
import { IndexRedirect } from '@/app/IndexRedirect';
import AppLayout from '@/components/AppLayout';
import Login from '@/pages/Login';
import NotFound from '@/pages/NotFound';

function moduleRoute(element: ReactNode): ReactNode {
  return <ModuleRouteGuard>{element}</ModuleRouteGuard>;
}

export const appRoutes: RouteObject[] = [
  {
    element: <AuthGuard />,
    children: [
      {
        path: APP_ROUTE_PATHS.home,
        element: <AppLayout />,
        children: [
          {
            index: true,
            element: <IndexRedirect />,
          },
      {
        path: APP_ROUTE_PATHS.dashboard.slice(1),
        element: moduleRoute(<DashboardPage />),
      },
      {
        path: APP_ROUTE_PATHS.frame.slice(1),
        element: moduleRoute(<FramePage />),
      },
      {
        path: APP_ROUTE_PATHS.classroom.slice(1),
        element: moduleRoute(<ClassroomSupportPage />),
      },
      {
        path: APP_ROUTE_PATHS.timer.slice(1),
        element: moduleRoute(<ClassroomTimerPage />),
      },
      {
        path: APP_ROUTE_PATHS.qbs.slice(1),
        element: moduleRoute(<QbsSafetyPage />),
      },
      {
        path: APP_ROUTE_PATHS.ei.slice(1),
        element: moduleRoute(<EmotionalIntelligencePage />),
      },
      {
        path: APP_ROUTE_PATHS.zones.slice(1),
        element: moduleRoute(<ZonesOfRegulationPage />),
      },
      {
        path: APP_ROUTE_PATHS.signs.slice(1),
        element: moduleRoute(<SignLanguagePage />),
      },
      {
        path: APP_ROUTE_PATHS.attendance.slice(1),
        element: moduleRoute(<CampusAttendancePage />),
      },
      {
        path: APP_ROUTE_PATHS.parentComm.slice(1),
        element: moduleRoute(<ParentCommunicationPage />),
      },
      {
        path: APP_ROUTE_PATHS.internalComm.slice(1),
        element: moduleRoute(<InternalAlertsPage />),
      },
      {
        path: APP_ROUTE_PATHS.safety.slice(1),
        element: moduleRoute(<SafetyProtocolsPage />),
      },
      {
        path: APP_ROUTE_PATHS.handbook.slice(1),
        element: moduleRoute(<HandbookPoliciesPage />),
      },
      {
        path: APP_ROUTE_PATHS.community.slice(1),
        element: moduleRoute(<CommunityPartnershipsPage />),
      },
      {
        path: APP_ROUTE_PATHS.vocational.slice(1),
        element: moduleRoute(<VocationalOpportunitiesPage />),
      },
      {
        path: APP_ROUTE_PATHS.esa.slice(1),
        element: moduleRoute(<EsaFundingPage />),
      },
      {
        path: APP_ROUTE_PATHS.walkthrough.slice(1),
        element: moduleRoute(<WalkthroughPage />),
      },
      {
        path: APP_ROUTE_PATHS.director.slice(1),
        element: moduleRoute(<DirectorDashboardPage />),
      },
        ],
      },
    ],
  },
  {
    path: APP_ROUTE_PATHS.login,
    element: <Login />,
  },
  {
    path: APP_ROUTE_PATHS.notFound,
    element: <NotFound />,
  },
];
