import { Suspense, useEffect } from 'react';
import { type RouteObject } from 'react-router';
import { Navigate, Outlet } from 'react-router-dom';

import { MassiveAssignProvider } from 'src/pages/dashboard/forms/MassiveAssignContext';
import { EventName } from 'src/types/amplitude';
import { CommunityFeature } from 'src/types/communityFeatures';
import { FeatureFlags } from 'src/types/featureFlags';
import { GroupsStepsType } from 'src/types/groups';
import { type MeUser } from 'src/types/user';
import { lazyRetry } from 'src/utils/lazyRetry';
import { hasAllPermissions, ROUTE_PERMISSIONS } from 'src/utils/permissions';
import { getDefaultRoute } from 'src/utils/routes';

import { chatRoutes } from 'src/components/dashboard/chat/routes';
import LoadingScreen from 'src/components/LoadingScreen';

import CommunityFeatureGuard from './components/guards/CommunityFeatureGuard';
import ManagerGuard from './components/guards/ManagerGuard';
import { SocketProvider } from './contexts/SocketContext';
import useFeatureFlag from './hooks/useFeatureFlag';
import { pxPaths, pxRoutes } from './pages/dashboard/PeopleExperience/routes';
import { ModuleConfigurationProvider } from './pages/dashboard/serviceManagement/contexts/ModuleConfigurationContext';
import { SportsPoolThemeProvider } from './pages/dashboard/sportsPool/context/SportsPoolThemeContext';
import { SPORTS_POOL_PATHS } from './pages/dashboard/sportsPool/routes';
import CompletedSurveyDetail from './pages/dashboard/surveys/CompletedSurveyDetail';
import SurveyCatalog from './pages/dashboard/surveys/SurveyCatalog';
import SurveyCompletion from './pages/dashboard/surveys/SurveyCompletion';

export const Loadable = (Component: React.ComponentType<any>) =>
  function LoadableComponent(props: any) {
    return (
      <Suspense fallback={<LoadingScreen />}>
        <Component {...props} />
      </Suspense>
    );
  };

// components
const AuthGuard = Loadable(
  lazyRetry(() => import('src/components/guards/AuthGuard')),
);
const DashboardLayout = Loadable(
  lazyRetry(() => import('./components/dashboard/DashboardLayout')),
);
const GuestGuard = Loadable(
  lazyRetry(() => import('src/components/guards/GuestGuard')),
);
const PermissionsGuard = Loadable(
  lazyRetry(() => import('src/components/guards/PermissionsGuard')),
);

// Authentication pages
const Login = Loadable(lazyRetry(() => import('./pages/authentication/Login')));
const LoginOTP = Loadable(
  lazyRetry(() => import('./pages/authentication/LoginOTP')),
);
const UpdatePassword = Loadable(
  lazyRetry(() => import('./pages/authentication/UpdatePassword')),
);

// Registration pages
const RegisterUser = Loadable(
  lazyRetry(() => import('./pages/registration/RegisterUser')),
);
const JoinByLink = Loadable(
  lazyRetry(() => import('./pages/registration/JoinByLink')),
);
const RestorePassword = Loadable(
  lazyRetry(() => import('./pages/registration/RestorePassword')),
);

// Feed
const Feed = Loadable(lazyRetry(() => import('./pages/dashboard/feed/Feed')));
const PostDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/feed/PostDetail')),
);
const PostEdit = Loadable(
  lazyRetry(() => import('./pages/dashboard/feed/PostEdit')),
);
const FeedPostSharePage = Loadable(
  lazyRetry(() => import('./pages/dashboard/feed/FeedPostSharePage')),
);
const FeedPostInsights = Loadable(
  lazyRetry(() => import('./pages/dashboard/feed/FeedPostInsights')),
);
const FeedPendingPostsApproval = Loadable(
  lazyRetry(() => import('./pages/dashboard/feed/FeedPendingPostsApproval')),
);
const PinnedPosts = Loadable(
  lazyRetry(() => import('./pages/dashboard/feed/PinnedPosts')),
);

const SearchResults = Loadable(
  lazyRetry(() => import('./pages/dashboard/search')),
);

const LiveStream = Loadable(
  lazyRetry(() => import('./pages/dashboard/liveStream')),
);

// Groups
const Groups = Loadable(lazyRetry(() => import('./pages/dashboard/groups')));
const Group = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/Group')),
);
const ManageGroup = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/ManageGroup')),
);
const CreateGroup = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/CreateGroup')),
);
const GroupPostDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/GroupPostDetail')),
);
const GroupPostEdit = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/GroupPostEdit')),
);
const GroupPostSharePage = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/GroupPostSharePage')),
);
const GroupPostInsights = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/GroupPostInsights')),
);
const GroupPinnedPosts = Loadable(
  lazyRetry(() => import('./pages/dashboard/groups/GroupPinnedPosts')),
);

// NemakEvents
const NemakEvents = Loadable(
  lazyRetry(() => import('./pages/dashboard/nemakEvents/Events')),
);
const NemakFormEvent = Loadable(
  lazyRetry(() => import('./pages/dashboard/nemakEvents/FormEvent')),
);
const NemakEvent = Loadable(
  lazyRetry(() => import('./pages/dashboard/nemakEvents/Event')),
);

// Events
const Events = Loadable(
  lazyRetry(() => import('./pages/dashboard/events/List')),
);
const Event = Loadable(
  lazyRetry(() => import('./pages/dashboard/events/Event')),
);
const NewEvent = Loadable(
  lazyRetry(() => import('./pages/dashboard/events/New')),
);
const EventEdit = Loadable(
  lazyRetry(() => import('./pages/dashboard/events/Event/Edit')),
);

// Marketplace
const Marketplace = Loadable(
  lazyRetry(() => import('./pages/dashboard/marketplace/Marketplace')),
);
const MyMarketplacePosts = Loadable(
  lazyRetry(() => import('./pages/dashboard/marketplace/MyMarketplacePosts')),
);

// News
const News = Loadable(lazyRetry(() => import('./pages/dashboard/news/News')));
const ArticleDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/news/ArticleDetail')),
);

const Community = Loadable(
  lazyRetry(() => import('./pages/newCommunity/NewCommunity')),
);

// Profile
const NewProfile = Loadable(
  lazyRetry(() => import('./pages/dashboard/profile/NewProfile')),
);

const OrgChart = Loadable(
  lazyRetry(() => import('./pages/dashboard/orgChart/OrgChart')),
);

// Chats V2
const Conversations = Loadable(
  lazyRetry(() => import('./pages/dashboard/Conversations/Conversations')),
);

const ConversationThread = Loadable(
  lazyRetry(() => import('./pages/dashboard/Conversations/ConversationThread')),
);

const ConversationsEmpty = Loadable(
  lazyRetry(() => import('./pages/dashboard/Conversations/ConversationsEmpty')),
);

const ConversationsNewGeneric = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/Conversations/ConversationsNewGeneric'),
  ),
);

const ConversationsNewGroup = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/Conversations/ConversationsNewGroup'),
  ),
);

// Chats
const Chats = Loadable(
  lazyRetry(() => import('./pages/dashboard/chats/Chats')),
);
const ChatEmpty = Loadable(
  lazyRetry(() => import('./pages/dashboard/chats/ChatEmpty')),
);
const ChatThread = Loadable(
  lazyRetry(() => import('./pages/dashboard/chats/ChatThread')),
);
const ChatNewGeneric = Loadable(
  lazyRetry(() => import('./pages/dashboard/chats/ChatNewGeneric')),
);
const ChatNewOneToOne = Loadable(
  lazyRetry(() => import('./pages/dashboard/chats/ChatNewOneToOne')),
);

const ChatNewGroup = Loadable(
  lazyRetry(() => import('./pages/dashboard/chats/ChatNewGroup')),
);
const ChatThreadInfo = Loadable(
  lazyRetry(() => import('./pages/dashboard/chats/ChatThreadInfo')),
);

const VideoCall = Loadable(
  lazyRetry(() => import('./pages/dashboard/videoCall')),
);
const IncomingCallPopupPage = Loadable(
  lazyRetry(() => import('./pages/dashboard/videoCall/IncomingCallPopupPage')),
);

// Widgets
const Files = Loadable(
  lazyRetry(() => import('./pages/dashboard/files/Files')),
);
const People = Loadable(lazyRetry(() => import('./pages/dashboard/People')));

const LibrariesRoutes = Loadable(
  lazyRetry(() => import('./pages/dashboard/HuLibraries/HuLibrariesRoutes')),
);

const LegacyLibrariesRoutes = Loadable(
  lazyRetry(() => import('./pages/dashboard/libraries/LegacyLibrariesRoutes')),
);

// TODO-[Dolphin]:Temporarily, remove this once the migration is complete.
const LibrariesEntry = () => {
  const isHuLibrariesEnabled = useFeatureFlag(
    FeatureFlags.VIEW_KNOWLEDGE_LIBRARIES_V2,
  );

  return isHuLibrariesEnabled ? <LibrariesRoutes /> : <LegacyLibrariesRoutes />;
};

// Forms
const Forms = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/Forms')),
);
const FormDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/FormDetail')),
);
const FormPdf = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/FormPdf')),
);
const FormAnswer = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/FormAnswer')),
);
const FormPdfAnswer = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/FormPdfAnswer')),
);
const FormThread = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/FormThread')),
);
const FormsRequests = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/FormsRequets')),
);
const FormApprovalWorkflow = Loadable(
  lazyRetry(() => import('./pages/dashboard/forms/FormApprovalWorkflow')),
);

// Vacations
const VacationCollaboratorView = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/timeOff/components/CollaboratorView'),
  ),
);

const UpdateRequestByMail = Loadable(
  lazyRetry(() => import('src/pages/dashboard/timeOff/UpdateRequestByMail')),
);

const VacationManagerView = Loadable(
  lazyRetry(() => import('src/pages/dashboard/timeOff/ManagerView')),
);
const TimeOffManagerGuard = Loadable(
  lazyRetry(() => import('src/components/guards/TimeOffManagerGuard')),
);

// Performance
const Performance = Loadable(
  lazyRetry(() => import('./pages/dashboard/performance/CyclesList')),
);
const PerformanceReview = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/performance/PerformanceReview/index'),
  ),
);
const PeerSelection = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/performance/PerformancePeerSelection'),
  ),
);
const CalibrationDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/performance/CalibrationDetail')),
);
const PerformanceExternalReview = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/performance/PerformanceExternalReview'),
  ),
);

// onBoarding
const OnBoarding = Loadable(
  lazyRetry(() => import('./pages/dashboard/onboarding/Onboarding')),
);
const CategoryDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/onboarding/CategoryDetail')),
);
const TaskDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/onboarding/TaskDetail')),
);
const QuizFormOnBoarding = Loadable(
  lazyRetry(() => import('./pages/dashboard/onboarding/QuizForm')),
);
const QuizResultsOnboarding = Loadable(
  lazyRetry(() => import('./pages/dashboard/onboarding/QuizResults')),
);

// Documents
const Documents = Loadable(
  lazyRetry(() => import('./pages/dashboard/documents/Documents')),
);
const LaComerDocuments = Loadable(
  lazyRetry(() => import('./pages/dashboard/documents/LaComerDocuments')),
);
const Folder = Loadable(
  lazyRetry(() => import('./pages/dashboard/documents/Folder')),
);
const Document = Loadable(
  lazyRetry(() => import('./pages/dashboard/documents/Document')),
);
const SignDocument = Loadable(
  lazyRetry(() => import('./pages/dashboard/documents/SignDocument')),
);

// Acknowledgements
const Acknowledgements = Loadable(
  lazyRetry(() => import('./pages/dashboard/acknowledgements')),
);
const Acknowledgement = Loadable(
  lazyRetry(() => import('./pages/dashboard/acknowledgements/Detail')),
);
const AcknowledgementExchanges = Loadable(
  lazyRetry(() => import('./pages/dashboard/acknowledgements/Exchanges')),
);

// Recognitions
const Recognitions = Loadable(
  lazyRetry(() => import('./pages/dashboard/recognitions/Recognitions')),
);
const CreateIdea = Loadable(
  lazyRetry(() => import('./pages/dashboard/recognitions/CreateIdea')),
);
const Ideas = Loadable(
  lazyRetry(() => import('./pages/dashboard/recognitions/Ideas')),
);
const IdeaDetail = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/recognitions/components/IdeaDetail'),
  ),
);
const Transactions = Loadable(
  lazyRetry(() => import('./pages/dashboard/recognitions/Transactions')),
);
const Products = Loadable(
  lazyRetry(() => import('./pages/dashboard/recognitions/Products')),
);

// Scorm
const ScormFolders = Loadable(
  lazyRetry(() => import('./pages/dashboard/scorm/Folders')),
);
const ScormPlayer = Loadable(
  lazyRetry(() => import('./pages/dashboard/scorm/ScormPlayer')),
);
const ScormCourses = Loadable(
  lazyRetry(() => import('./pages/dashboard/scorm/Courses')),
);

// People experience (Px)
const PxCollaboratorSurveys = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/PeopleExperience/CollaboratorSurveys'),
  ),
);
const PxCollaboratorSurvey = Loadable(
  lazyRetry(() => import('./pages/dashboard/PeopleExperience/Survey')),
);
const PxManagerSurveys = Loadable(
  lazyRetry(() => import('./pages/dashboard/PeopleExperience/ManagerSurveys')),
);
const PxManagerResults = Loadable(
  lazyRetry(() => import('./pages/dashboard/PeopleExperience/ManagerResults')),
);
const PxManagerResultsExperimental = Loadable(
  lazyRetry(
    () =>
      import('./pages/dashboard/PeopleExperience/experimental/ManagerResults'),
  ),
);
const PxManagerResultsParticipation = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/PeopleExperience/experimental/ManagerResults/components/ParticipationResults'
      ),
  ),
);
export const PxManagerResultsEnps = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/PeopleExperience/experimental/ManagerResults/components/EnpsResults'
      ),
  ),
);
export const PxManagerResultsList = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/PeopleExperience/experimental/ManagerResults/components/ListResults'
      ),
  ),
);
export const PxManagerResultsHeatmap = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/PeopleExperience/experimental/ManagerResults/components/HeatmapResults'
      ),
  ),
);

const NotificationsConfig = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/notifications/NotificationsConfig'),
  ),
);

// Goals
const Goals = Loadable(
  lazyRetry(() => import('./pages/dashboard/goals/Goals')),
);

const GoalDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/goals/GoalDetail')),
);

const NewGoal = Loadable(
  lazyRetry(() => import('./pages/dashboard/goals/NewGoal')),
);

const IndividualGoals = Loadable(
  lazyRetry(() => import('./pages/dashboard/goals/TeamGoals')),
);

// Courses
const CoursesList = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/courses/List')),
);

const CourseDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/courses/Detail')),
);

const CourseTasks = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/courses/Tasks')),
);

const CourseCompletion = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/courses/Completion')),
);

const CourseSign = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/courses/Sign')),
);

const LearningLacomerCourses = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/lacomer/Courses')),
);

const LearningLacomerCoursesCurriculum = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/learning/lacomer/CoursesCurriculum'),
  ),
);

// Paths
const PathsList = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/paths/List')),
);

const PathDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/paths/Detail')),
);

const PathCompletion = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/paths/Completion')),
);

// Sessions
const SessionsList = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/sessions/List')),
);

const SessionDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/learning/sessions/Detail')),
);

// Time Tracking

const TimeTrackingModuleGuard = Loadable(
  lazyRetry(() => import('src/components/guards/TimeTrackingGuard')),
);

const ClockGuard = Loadable(
  lazyRetry(() => import('src/components/guards/ClockGuard')),
);

const TimeTrackingBaseRoute = Loadable(
  lazyRetry(() => import('./pages/dashboard/timeTracking/BaseLayout')),
);

const TimeTracking = Loadable(
  lazyRetry(() => import('./pages/dashboard/timeTracking')),
);

const PeriodCollaborators = Loadable(
  lazyRetry(() => import('./pages/dashboard/timeTracking/PeriodCollaborators')),
);

const EmployeeTimesheet = Loadable(
  lazyRetry(() => import('./pages/dashboard/timeTracking/EmployeeTimesheet')),
);

const OvertimeApprovalRequests = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/timeTracking/OvertimeApprovalRequests'),
  ),
);

// Employee Lifecycle
const EmployeeLifecycle = Loadable(
  lazyRetry(() => import('./pages/dashboard/employeeLifecycle')),
);

const EmployeeLifecycleSteps = Loadable(
  lazyRetry(() => import('./pages/dashboard/employeeLifecycle/Journeys/Steps')),
);

const EmployeeLifecycleJourneyTasks = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/employeeLifecycle/Tasks/JourneyTasks'),
  ),
);

const EmployeeLifecycleUserTasks = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/employeeLifecycle/Tasks/UserTasks'),
  ),
);

const EmployeeLifecycleFormTask = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/employeeLifecycle/Tasks/components/Form'),
  ),
);

const EmployeeLifecycleFormResults = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/employeeLifecycle/Tasks/components/Form/FormResults'
      ),
  ),
);

// BanBajio

const BanBajioCustomErrorBoundary = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/banBajio/components/CustomErrorBoundary'),
  ),
);

const BanBajioRequests = Loadable(
  lazyRetry(() => import('./pages/dashboard/banBajio/Requests')),
);

const BanBajioLoanRequests = Loadable(
  lazyRetry(() => import('./pages/dashboard/banBajio/LoanRequests')),
);

const BanBajioFormAdvancePayment = Loadable(
  lazyRetry(() => import('./pages/dashboard/banBajio/FormAdvancePayment')),
);

const BanBajioLibraryFullScreen = Loadable(
  lazyRetry(() => import('./pages/dashboard/banBajio/LibraryFullScreen')),
);

// Payroll Mobility ADO
const PayrollMobilityAdoPage = Loadable(
  lazyRetry(() => import('./pages/dashboard/payrollMobilityAdo')),
);

// Microloans

const Microloans = Loadable(
  lazyRetry(() => import('./pages/dashboard/microloans')),
);
const MicroloansRequestOffer = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/microloans/components/RequestOffer'),
  ),
);
const MicroloansStatus = Loadable(
  lazyRetry(() => import('./pages/dashboard/microloans/components/Status')),
);
const MicroloansHistory = Loadable(
  lazyRetry(() => import('./pages/dashboard/microloans/components/History')),
);
const MicroloansIndexRedirect = Loadable(
  lazyRetry(
    () =>
      import('./pages/dashboard/microloans/components/MicroloansIndexRedirect'),
  ),
);

// Service Management
const ServicePortal = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/serviceManagement/servicePortal/Requests'),
  ),
);

const ServiceItems = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/serviceManagement/servicePortal/serviceItems/ServiceItems'
      ),
  ),
);

const ServiceItem = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/serviceManagement/servicePortal/serviceItem/ServiceItem'
      ),
  ),
);

const ServiceItemDetails = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/serviceManagement/servicePortal/requestedDetails/ServiceItemDetails'
      ),
  ),
);

const ApprovalsPortal = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/serviceManagement/servicePortal/approvals/ApprovalsPortal'
      ),
  ),
);

const AgentWorkspace = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/serviceManagement/agentWorkspace/AgentWorkspace'
      ),
  ),
);

const ServiceMgmtModuleConfigurationLayout: React.FC = () => {
  return (
    <ModuleConfigurationProvider>
      <Outlet />
    </ModuleConfigurationProvider>
  );
};

// Communication
const DraftsForReview = Loadable(
  lazyRetry(() => import('./pages/dashboard/communication/DraftsForReview')),
);

const NewDraft = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/communication/DraftsForReview/NewDraft'),
  ),
);

const DraftDetail = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/communication/DraftsForReview/DraftDetail'),
  ),
);

const DraftEdit = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/communication/DraftsForReview/DraftEdit'),
  ),
);

const KeyUpdates = Loadable(
  lazyRetry(() => import('./pages/dashboard/feed/KeyUpdatesPage')),
);

// Shifts

const Shifts = Loadable(lazyRetry(() => import('./pages/dashboard/shifts')));
const ShiftsRepository = Loadable(
  lazyRetry(
    () => import('./pages/dashboard/shifts/components/ShiftsRepository'),
  ),
);
const CreateShiftRotation = Loadable(
  lazyRetry(
    () =>
      import(
        './pages/dashboard/shifts/components/ShiftsRepository/CreateShiftRotation'
      ),
  ),
);

// Clock

const Clock = Loadable(lazyRetry(() => import('./pages/dashboard/clock')));

// Sports Pool (Prode)
const SportsPoolCompetitions = Loadable(
  lazyRetry(() => import('./pages/dashboard/sportsPool/Competitions')),
);
const SportsPoolCompetitionDetail = Loadable(
  lazyRetry(() => import('./pages/dashboard/sportsPool/CompetitionDetail')),
);
const SportsPoolPodiumPage = Loadable(
  lazyRetry(() => import('./pages/dashboard/sportsPool/PodiumPage')),
);

const SportsPoolMobileIndexRedirect = () => (
  <Navigate
    to={SPORTS_POOL_PATHS.COMPETITIONS}
    replace
  />
);

// Preloads all sports pool chunks on webview entry to avoid the Suspense
// fallback (white flash) in dark mode during navigation.
const SportsPoolMobilePreloader = () => {
  useEffect(() => {
    import('./pages/dashboard/sportsPool/Competitions');
    import('./pages/dashboard/sportsPool/CompetitionDetail');
    import('./pages/dashboard/sportsPool/PodiumPage');
  }, []);
  return (
    <SportsPoolThemeProvider>
      <Outlet />
    </SportsPoolThemeProvider>
  );
};

const routes = (permissions: string[], user: MeUser | null): RouteObject[] => {
  const hasNewChat = hasAllPermissions(
    permissions,
    ROUTE_PERMISSIONS.CONVERSATIONS,
  );

  const oldChats = [
    {
      path: 'chats',
      defaultPathIf: ROUTE_PERMISSIONS.CHATS,
      element: (
        <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CHATS}>
          <Chats />
        </PermissionsGuard>
      ),
      children: [
        {
          path: ':id',
          element: (
            <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CHATS}>
              <ChatThread />
            </PermissionsGuard>
          ),
        },
        {
          path: ':id/info',
          element: (
            <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CHATS}>
              <ChatThreadInfo />
            </PermissionsGuard>
          ),
        },
        {
          index: true,
          element: (
            <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CHATS}>
              <ChatEmpty />
            </PermissionsGuard>
          ),
        },
      ],
    },
    {
      path: 'topics',
      defaultPathIf: ROUTE_PERMISSIONS.CHATS,
      children: [
        {
          path: ':id',
          element: (
            <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CHATS}>
              <Navigate
                to={chatRoutes.new.ticket()}
                replace
              />
            </PermissionsGuard>
          ),
        },
        {
          index: true,
          element: (
            <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CHATS}>
              <Navigate
                to={chatRoutes.new.ticket()}
                replace
              />
            </PermissionsGuard>
          ),
        },
      ],
    },
    {
      path: 'chats/new',
      defaultPathIf: ROUTE_PERMISSIONS.CHATS,
      children: [
        {
          path: 'generic',
          element: (
            <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CHATS}>
              <ChatNewGeneric />
            </PermissionsGuard>
          ),
        },
        {
          path: 'oneToOne',
          element: (
            <PermissionsGuard
              requiredPermissions={ROUTE_PERMISSIONS.NEW_ONE_TO_ONE}
              strict
            >
              <ChatNewOneToOne />
            </PermissionsGuard>
          ),
        },
        {
          path: 'group',
          element: (
            <PermissionsGuard
              requiredPermissions={ROUTE_PERMISSIONS.NEW_GROUP}
              strict
            >
              <ChatNewGroup />
            </PermissionsGuard>
          ),
        },
      ],
    },
  ];

  const newChats = [
    {
      path: 'conversations',
      defaultPathIf: ROUTE_PERMISSIONS.CONVERSATIONS,
      element: (
        <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.CONVERSATIONS}>
          <Conversations />
        </PermissionsGuard>
      ),
      children: [
        {
          path: ':id',
          element: (
            <PermissionsGuard
              requiredPermissions={ROUTE_PERMISSIONS.CONVERSATIONS}
            >
              <ConversationThread />
            </PermissionsGuard>
          ),
        },
        {
          index: true,
          element: (
            <PermissionsGuard
              requiredPermissions={ROUTE_PERMISSIONS.CONVERSATIONS}
            >
              <ConversationsEmpty />
            </PermissionsGuard>
          ),
        },
      ],
    },
    {
      path: 'conversations/new',
      defaultPathIf: ROUTE_PERMISSIONS.CONVERSATIONS,
      children: [
        {
          index: true,
          element: (
            <PermissionsGuard
              requiredPermissions={ROUTE_PERMISSIONS.CONVERSATIONS}
            >
              <ConversationsNewGeneric />
            </PermissionsGuard>
          ),
        },
        {
          path: 'group',
          element: (
            <PermissionsGuard
              requiredPermissions={ROUTE_PERMISSIONS.CONVERSATIONS}
            >
              <ConversationsNewGroup />
            </PermissionsGuard>
          ),
        },
      ],
    },
  ];

  const chatModule = hasNewChat ? newChats : oldChats;

  const dashboardRoutes = {
    path: '/',
    element: (
      <AuthGuard>
        <DashboardLayout />
      </AuthGuard>
    ),
    children: [
      {
        path: 'feed',
        defaultPathIf: ROUTE_PERMISSIONS.FEED,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <Feed />
              </PermissionsGuard>
            ),
          },
          {
            path: 'live-stream',
            element: (
              <PermissionsGuard
                //TODO: replace with ROUTE_PERMISSIONS.LIVESTREAM in the future
                requiredPermissions={ROUTE_PERMISSIONS.FEED}
              >
                <LiveStream />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <PostDetail />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/edit',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <PostEdit />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/share',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <FeedPostSharePage />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/insights',
            element: (
              <CommunityFeatureGuard
                requiredCommunityFeature={CommunityFeature.VIEW_POST_STATS}
              >
                <FeedPostInsights />
              </CommunityFeatureGuard>
            ),
          },
          {
            path: 'pending-posts',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.FEED_PENDING_POSTS}
              >
                <FeedPendingPostsApproval />
              </PermissionsGuard>
            ),
          },
          {
            path: 'pinned-posts',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <PinnedPosts />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'groups',
        defaultPathIf: ROUTE_PERMISSIONS.GROUPS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <Groups />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <Group />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/configuration',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <ManageGroup />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/configuration/manageMembers',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <Navigate
                  to={`/groups/${location.pathname.split('/')[2]}/configuration?type=${GroupsStepsType.INVITATION_MANAGEMENT}`}
                  replace
                />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/configuration/managePostsApproval',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <Navigate
                  to={`/groups/${location.pathname.split('/')[2]}/configuration?type=${GroupsStepsType.PENDING_POSTS_APPROVAL}`}
                  replace
                />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/live-stream',
            element: (
              <PermissionsGuard
                //TODO: replace with ROUTE_PERMISSIONS.LIVESTREAM in the future
                requiredPermissions={ROUTE_PERMISSIONS.GROUPS}
              >
                <LiveStream />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/pinned-posts',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <GroupPinnedPosts />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/post/:postId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <GroupPostDetail />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/post/:postId/edit',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <GroupPostEdit />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/post/:postId/share',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GROUPS}>
                <GroupPostSharePage />
              </PermissionsGuard>
            ),
          },
          {
            path: 'create',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.CREATE_GROUPS}
              >
                <CreateGroup />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/post/:postId/insights',
            element: (
              <CommunityFeatureGuard
                requiredCommunityFeature={CommunityFeature.VIEW_POST_STATS}
              >
                <GroupPostInsights />
              </CommunityFeatureGuard>
            ),
          },
        ],
      },
      {
        path: 'search',
        //TODO: add community feature guard
        element: <SearchResults />,
      },
      {
        path: 'service-portal',
        defaultPathIf: ROUTE_PERMISSIONS.WORKFLOWS,
        element: (
          <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.WORKFLOWS}>
            <ServiceMgmtModuleConfigurationLayout />
          </PermissionsGuard>
        ),
        children: [
          {
            index: true,
            element: <ServicePortal />,
          },
          {
            path: 'service-items',
            element: <ServiceItems />,
          },
          {
            path: 'service-items/:id',
            element: <ServiceItem />,
          },
          {
            path: 'service-items/:id/detail',
            element: <ServiceItemDetails />,
          },
          {
            path: 'requests/:id',
            element: <ServiceItemDetails />,
          },
          {
            path: 'approvals',
            element: <ApprovalsPortal />,
          },
        ],
      },
      {
        path: 'agent-workspace',
        defaultPathIf: ROUTE_PERMISSIONS.WORKFLOWS,
        element: (
          <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.WORKFLOWS}>
            <ServiceMgmtModuleConfigurationLayout />
          </PermissionsGuard>
        ),
        children: [
          {
            index: true,
            element: <AgentWorkspace />,
          },
          {
            path: 'views/:viewId',
            element: <AgentWorkspace />,
          },
          {
            path: 'coordinator-panel',
            element: <AgentWorkspace />,
          },
          {
            path: 'approvals',
            element: <AgentWorkspace />,
          },
          {
            path: 'tasks',
            element: <AgentWorkspace />,
          },
          {
            path: 'tickets/:id',
            element: <ServiceItemDetails isAgentSide={true} />,
          },
        ],
      },
      {
        path: 'requests-banbajio',
        defaultPathIf: ROUTE_PERMISSIONS.FEED,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <BanBajioCustomErrorBoundary>
                  <BanBajioRequests />
                </BanBajioCustomErrorBoundary>
              </PermissionsGuard>
            ),
          },
          {
            path: 'loan',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <BanBajioCustomErrorBoundary>
                  <BanBajioLoanRequests />
                </BanBajioCustomErrorBoundary>
              </PermissionsGuard>
            ),
          },
          {
            path: 'advancePayment',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <BanBajioCustomErrorBoundary>
                  <BanBajioFormAdvancePayment />
                </BanBajioCustomErrorBoundary>
              </PermissionsGuard>
            ),
          },
          {
            path: 'mortgageLibrary',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <BanBajioCustomErrorBoundary>
                  <BanBajioLibraryFullScreen />
                </BanBajioCustomErrorBoundary>
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'payroll-mobility-ado',
        defaultPathIf: ROUTE_PERMISSIONS.PAYROLL_MOBILITY_ADO,
        element: (
          <PermissionsGuard
            requiredPermissions={ROUTE_PERMISSIONS.PAYROLL_MOBILITY_ADO}
          >
            <PayrollMobilityAdoPage />
          </PermissionsGuard>
        ),
      },
      {
        path: 'microloans',
        defaultPathIf: ROUTE_PERMISSIONS.MICROLOANS,
        element: (
          <PermissionsGuard requiredPermissions={[]}>
            <CommunityFeatureGuard
              requiredCommunityFeature={CommunityFeature.VIEW_MICROLOANS}
            >
              <Microloans />
            </CommunityFeatureGuard>
          </PermissionsGuard>
        ),
        children: [
          {
            index: true,
            element: <MicroloansIndexRedirect />,
          },
          {
            path: 'request-offer',
            element: <MicroloansRequestOffer />,
          },
          {
            path: 'status',
            element: <MicroloansStatus />,
          },
          {
            path: 'history',
            element: <MicroloansHistory />,
          },
        ],
      },
      {
        path: 'events-nemak',
        defaultPathIf: ROUTE_PERMISSIONS.EVENTS_NEMAK,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EVENTS_NEMAK}
              >
                <NemakEvents />
              </PermissionsGuard>
            ),
          },
          {
            path: ':eventId',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EVENTS_NEMAK}
              >
                <NemakEvent />
              </PermissionsGuard>
            ),
          },
          {
            path: ':formId/:employeeId',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EVENTS_NEMAK}
              >
                <NemakFormEvent />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'events',
        defaultPathIf: ROUTE_PERMISSIONS.EVENTS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.EVENTS}>
                <Events />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.EVENTS}>
                <Event />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/edit',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.MANAGE_EVENTS}
              >
                <EventEdit />
              </PermissionsGuard>
            ),
          },
          {
            path: 'new',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.MANAGE_EVENTS}
              >
                <NewEvent />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/live-stream',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.LIVESTREAM}
              >
                <LiveStream />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'scorm-folders',
        defaultPathIf: ROUTE_PERMISSIONS.SCORMS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.SCORMS}>
                <ScormFolders />
              </PermissionsGuard>
            ),
          },
          {
            path: 'scorm-player/:courseId/:registrationId/:folderName',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.SCORMS}>
                <ScormPlayer />
              </PermissionsGuard>
            ),
          },
          {
            path: 'folder/:folderId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.SCORMS}>
                <ScormCourses />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'events-nemak-mobile/:accessToken',
        defaultPathIf: ROUTE_PERMISSIONS.EVENTS_NEMAK,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EVENTS_NEMAK}
              >
                <NemakEvents />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'recognitions-nemak',
        defaultPathIf: ROUTE_PERMISSIONS.RECOGNITIONS_NEMAK,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.RECOGNITIONS_NEMAK}
              >
                <Recognitions />
              </PermissionsGuard>
            ),
          },
          {
            path: 'createIdea',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.RECOGNITIONS_NEMAK}
              >
                <CreateIdea />
              </PermissionsGuard>
            ),
          },
          {
            path: 'ideas',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.RECOGNITIONS_NEMAK}
              >
                <Ideas />
              </PermissionsGuard>
            ),
          },
          {
            path: 'idea/:ideaId',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.RECOGNITIONS_NEMAK}
              >
                <IdeaDetail />
              </PermissionsGuard>
            ),
          },
          {
            path: 'transactions',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.RECOGNITIONS_NEMAK}
              >
                <Transactions />
              </PermissionsGuard>
            ),
          },
          {
            path: 'products',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <Products />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'news',
        defaultPathIf: ROUTE_PERMISSIONS.NEWS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.NEWS}>
                <News />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.NEWS}>
                <ArticleDetail eventNameAmplitude={EventName.ARTICLE_VIEW} />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'goals',
        defaultPathIf: ROUTE_PERMISSIONS.GOALS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GOALS}>
                <Goals />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GOALS}>
                <GoalDetail />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/edit',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GOALS}>
                <NewGoal />
              </PermissionsGuard>
            ),
          },
          {
            path: 'new',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GOALS}>
                <NewGoal />
              </PermissionsGuard>
            ),
          },
          {
            path: 'team/:id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.GOALS}>
                <IndividualGoals />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'performance',
        defaultPathIf: ROUTE_PERMISSIONS.PERFORMANCE,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PERFORMANCE}
              >
                <Performance />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PERFORMANCE}
              >
                <PerformanceReview />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/peer',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PERFORMANCE}
              >
                <PeerSelection />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/calibration/:formReviewId',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PERFORMANCE}
              >
                <CalibrationDetail />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'notifications-config',
        defaultPathIf: ROUTE_PERMISSIONS.FEED,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
                <NotificationsConfig />
              </PermissionsGuard>
            ),
          },
        ],
      },
      ...chatModule,
      {
        path: 'acknowledgements',
        defaultPathIf: ROUTE_PERMISSIONS.USER_ACKNOWLEDGEMENTS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.USER_ACKNOWLEDGEMENTS}
              >
                <Acknowledgements />
              </PermissionsGuard>
            ),
          },
          {
            path: 'exchanges',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.USER_ACKNOWLEDGEMENTS}
              >
                <AcknowledgementExchanges />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.USER_ACKNOWLEDGEMENTS}
              >
                <Acknowledgement />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'org-chart',
        defaultPathIf: ROUTE_PERMISSIONS.ORG_CHART,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.ORG_CHART}
              >
                <OrgChart />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.ORG_CHART}
              >
                <OrgChart />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'forms',
        defaultPathIf: ROUTE_PERMISSIONS.FORMS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <Forms />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <FormDetail isEdition={false} />
              </PermissionsGuard>
            ),
          },
          {
            path: 'pdf/:id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <FormPdf />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/chat',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <ChatThread />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id/approval-workflow',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <FormApprovalWorkflow />
              </PermissionsGuard>
            ),
          },
          {
            path: ':templateId/completed/:answerId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <FormAnswer />
              </PermissionsGuard>
            ),
          },
          {
            path: ':templateId/edit/:answerId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <FormDetail isEdition />
              </PermissionsGuard>
            ),
          },
          {
            path: 'pdf/:templateId/completed/:answerId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <FormPdfAnswer />
              </PermissionsGuard>
            ),
          },
          {
            path: 'requests',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FORMS}>
                <MassiveAssignProvider>
                  <FormsRequests />
                </MassiveAssignProvider>
              </PermissionsGuard>
            ),
            children: [
              {
                index: true,
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.FORMS}
                  >
                    <ChatEmpty type="forms" />
                  </PermissionsGuard>
                ),
              },
              {
                path: ':id',
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.FORMS}
                  >
                    <FormThread />
                  </PermissionsGuard>
                ),
              },
              {
                path: ':id/approval-workflow',
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.FORMS}
                  >
                    <FormApprovalWorkflow />
                  </PermissionsGuard>
                ),
              },
            ],
          },
        ],
      },
      {
        path: 'vacations',
        defaultPathIf: ROUTE_PERMISSIONS.VACATIONS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.VACATIONS}
              >
                <VacationCollaboratorView />
              </PermissionsGuard>
            ),
          },
          {
            path: 'manager',
            element: (
              <TimeOffManagerGuard>
                <VacationManagerView />
              </TimeOffManagerGuard>
            ),
          },
        ],
      },
      {
        path: 'people',
        defaultPathIf: ROUTE_PERMISSIONS.PEOPLE,
        element: (
          <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.PEOPLE}>
            <People />
          </PermissionsGuard>
        ),
      },
      {
        path: 'files',
        defaultPathIf: ROUTE_PERMISSIONS.FILES,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FILES}>
                <Files />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FILES}>
                <Files />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'onboarding',
        defaultPathIf: ROUTE_PERMISSIONS.ONBOARDING,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.ONBOARDING}
              >
                <OnBoarding />
              </PermissionsGuard>
            ),
          },
          {
            path: ':categoryId',
            children: [
              {
                index: true,
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.ONBOARDING}
                  >
                    <CategoryDetail />
                  </PermissionsGuard>
                ),
              },
              {
                path: 'tasks/:taskId',
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.ONBOARDING}
                  >
                    <TaskDetail />
                  </PermissionsGuard>
                ),
              },
              {
                path: 'tasks/:taskId/complete',
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.ONBOARDING}
                  >
                    <QuizFormOnBoarding />
                  </PermissionsGuard>
                ),
              },
              {
                path: 'tasks/:taskId/results',
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.ONBOARDING}
                  >
                    <QuizResultsOnboarding />
                  </PermissionsGuard>
                ),
              },
            ],
          },
        ],
      },
      {
        path: 'surveys',
        defaultPathIf: ROUTE_PERMISSIONS.SURVEYS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.SURVEYS}>
                <SurveyCatalog />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.SURVEYS}>
                <SurveyCompletion />
              </PermissionsGuard>
            ),
          },
          {
            path: ':templateId/completed/:answerId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.SURVEYS}>
                <CompletedSurveyDetail />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'documents',
        defaultPathIf: ROUTE_PERMISSIONS.DOCUMENTS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.DOCUMENTS}
              >
                <Documents />
              </PermissionsGuard>
            ),
          },
          {
            path: ':folderId',
            children: [
              {
                index: true,
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.DOCUMENTS}
                  >
                    <Folder />
                  </PermissionsGuard>
                ),
              },
              {
                path: 'files/:documentId',
                element: (
                  <PermissionsGuard
                    requiredPermissions={ROUTE_PERMISSIONS.DOCUMENTS}
                  >
                    <Document />
                  </PermissionsGuard>
                ),
              },
            ],
          },
          {
            path: 'pending/files/:id',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.DOCUMENTS}
              >
                <SignDocument />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'lacomer',
        children: [
          {
            index: true,
            element: (
              <Navigate
                to="courses"
                replace
              />
            ),
          },
          {
            path: 'courses',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.COURSES}>
                <LearningLacomerCourses />
              </PermissionsGuard>
            ),
          },
          {
            path: 'courses-curriculum',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.COURSES}>
                <LearningLacomerCoursesCurriculum />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'courses',
        defaultPathIf: ROUTE_PERMISSIONS.COURSES,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.COURSES}
              >
                <CoursesList />
              </PermissionsGuard>
            ),
          },
          {
            path: ':courseId',
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.COURSES}
              >
                <CourseDetail />
              </PermissionsGuard>
            ),
          },
          {
            path: ':courseId/lessons/:taskId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.COURSES}>
                <CourseTasks />
              </PermissionsGuard>
            ),
          },
          {
            path: ':courseId/completion',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.COURSES}>
                <CourseCompletion />
              </PermissionsGuard>
            ),
          },
          {
            path: ':courseId/sign',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.COURSES}>
                <CourseSign />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'paths',
        defaultPathIf: ROUTE_PERMISSIONS.PATHS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.PATHS}
              >
                <PathsList />
              </PermissionsGuard>
            ),
          },
          {
            path: ':pathId',
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.PATHS}
              >
                <PathDetail />
              </PermissionsGuard>
            ),
          },
          {
            path: ':pathId/completion',
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.PATHS}
              >
                <PathCompletion />
              </PermissionsGuard>
            ),
          },
          {
            path: ':pathId/courses/:courseId',
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.COURSES}
              >
                <CourseDetail />
              </PermissionsGuard>
            ),
          },
          {
            path: ':pathId/courses/:courseId/lessons/:taskId',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.PATHS}>
                <CourseTasks />
              </PermissionsGuard>
            ),
          },
          {
            path: ':pathId/courses/:courseId/completion',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.PATHS}>
                <CourseCompletion />
              </PermissionsGuard>
            ),
          },
          {
            path: ':pathId/courses/:courseId/sign',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.PATHS}>
                <CourseSign />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'sessions',
        defaultPathIf: ROUTE_PERMISSIONS.SESSIONS,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.SESSIONS}
              >
                <SessionsList />
              </PermissionsGuard>
            ),
          },
          {
            path: ':id',
            element: (
              <PermissionsGuard
                strict
                requiredPermissions={ROUTE_PERMISSIONS.SESSIONS}
              >
                <SessionDetail />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'marketplace',
        defaultPathIf: ROUTE_PERMISSIONS.MARKETPLACE,
        children: [
          {
            index: true,
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.MARKETPLACE}
              >
                <Marketplace />
              </PermissionsGuard>
            ),
          },
          {
            path: 'mine',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.MARKETPLACE}
              >
                <MyMarketplacePosts />
              </PermissionsGuard>
            ),
          },
        ],
      },
      // Low priority: no tienen una route root y requieren de un id.
      {
        path: 'profile',
        defaultPathIf: ROUTE_PERMISSIONS.PROFILE,
        children: [
          {
            path: ':id',
            element: (
              <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.PROFILE}>
                <NewProfile />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'library/*',
        defaultPathIf: ROUTE_PERMISSIONS.KNOWLEDGE_LIBRARY,
        element: <LibrariesEntry />,
      },
      {
        path: pxRoutes.base(),
        defaultPathIf: ROUTE_PERMISSIONS.PEOPLE_EXPERIENCE,
        children: [
          {
            path: pxRoutes.collaboratorSurveysBase(),
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PEOPLE_EXPERIENCE}
              >
                <PxCollaboratorSurveys />
              </PermissionsGuard>
            ),
          },
          {
            path: pxRoutes.collaboratorSurvey(),
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PEOPLE_EXPERIENCE}
              >
                <PxCollaboratorSurvey />
              </PermissionsGuard>
            ),
          },
          {
            path: pxRoutes.managerSurveysBase(),
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PEOPLE_EXPERIENCE}
              >
                <PxManagerSurveys />
              </PermissionsGuard>
            ),
          },
          {
            path: pxRoutes.surveyManagerResults(),
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PEOPLE_EXPERIENCE}
              >
                <PxManagerResults />
              </PermissionsGuard>
            ),
          },
          {
            path: pxRoutes.surveyManagerResultsExperimental(),
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.PEOPLE_EXPERIENCE}
              >
                <PxManagerResultsExperimental />
              </PermissionsGuard>
            ),
            children: [
              {
                index: true,
                element: (
                  <Navigate
                    to={pxPaths.managerResultsParticipation}
                    replace
                  />
                ),
              },
              {
                path: pxPaths.managerResultsParticipation,
                element: <PxManagerResultsParticipation />,
              },
              {
                path: pxPaths.managerResultsNps,
                element: <PxManagerResultsEnps />,
              },
              {
                path: pxPaths.managerResultsList,
                element: <PxManagerResultsList />,
              },
              {
                path: pxPaths.managerResultsHeatmap,
                element: <PxManagerResultsHeatmap />,
              },
            ],
          },
        ],
      },
      {
        path: 'employee-lifecycle',
        defaultPathIf: ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE,
        children: [
          {
            index: true,
            element: (
              <Navigate
                to="onboardings"
                replace
              />
            ),
          },
          {
            path: 'onboardings',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycle />
              </PermissionsGuard>
            ),
          },
          {
            path: 'onboardings/:journeyId/steps',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycleSteps />
              </PermissionsGuard>
            ),
          },
          {
            path: 'onboardings/:journeyId/steps/:stepId/tasks',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycleJourneyTasks />
              </PermissionsGuard>
            ),
          },
          {
            path: 'onboardings/:journeyId/steps/:stepId/tasks/:taskId',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycleJourneyTasks />
              </PermissionsGuard>
            ),
          },
          {
            path: 'form/:taskId/:tag/:progressionId',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycleFormTask />
              </PermissionsGuard>
            ),
          },
          {
            path: 'form/:tag/:answerId/:answerToken/results',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycleFormResults />
              </PermissionsGuard>
            ),
          },
          {
            path: 'tasks',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycleUserTasks />
              </PermissionsGuard>
            ),
          },
          {
            path: 'tasks/:taskId',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.EMPLOYEE_LIFECYCLE}
              >
                <EmployeeLifecycleUserTasks />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'time-tracking',
        defaultPathIf: ROUTE_PERMISSIONS.TIME_TRACKING,
        element: (
          <TimeTrackingModuleGuard>
            <TimeTrackingBaseRoute />
          </TimeTrackingModuleGuard>
        ),
        children: [
          {
            path: '',
            element: <TimeTracking />,
            children: [
              {
                index: true,
                element: (
                  <Navigate
                    to="collaborators"
                    replace
                  />
                ),
              },
              {
                path: 'collaborators',
                element: <PeriodCollaborators />,
              },
              {
                path: 'overtime-requests',
                element: <OvertimeApprovalRequests />,
              },
            ],
          },
          {
            path: 'collaborators/:id',
            element: <EmployeeTimesheet />,
          },
        ],
      },
      {
        path: 'key-updates',
        element: (
          <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.KEY_UPDATES}>
            <KeyUpdates />
          </PermissionsGuard>
        ),
      },
      {
        path: 'shifts',
        defaultPathIf: ROUTE_PERMISSIONS.SHIFTS,
        children: [
          {
            index: true,
            element: (
              <ManagerGuard
                managerPermissions={ROUTE_PERMISSIONS.SHIFTS_BOSS}
                nonManagerPermissions={ROUTE_PERMISSIONS.SHIFTS}
              >
                <Shifts />
              </ManagerGuard>
            ),
          },
          {
            path: 'repository',
            element: (
              <Navigate
                to="/shifts/repository/individual-shifts"
                replace
              />
            ),
          },
          {
            path: 'repository/individual-shifts',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.SHIFTS_BOSS}
              >
                <ShiftsRepository />
              </PermissionsGuard>
            ),
          },
          {
            path: 'repository/templates',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.SHIFTS_BOSS}
              >
                <ShiftsRepository />
              </PermissionsGuard>
            ),
          },
          {
            path: 'repository/templates/new',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.SHIFTS_BOSS}
              >
                <CreateShiftRotation />
              </PermissionsGuard>
            ),
          },
          {
            path: 'repository/templates/:id/edit',
            element: (
              <PermissionsGuard
                requiredPermissions={ROUTE_PERMISSIONS.SHIFTS_BOSS}
              >
                <CreateShiftRotation />
              </PermissionsGuard>
            ),
          },
        ],
      },
      {
        path: 'clock',
        element: (
          <ClockGuard>
            <Clock />
          </ClockGuard>
        ),
      },
      {
        path: 'communication',
        children: [
          {
            index: true,
            element: (
              <Navigate
                to={'./drafts'}
                replace
              />
            ),
          },
          {
            path: 'drafts',
            element: <DraftsForReview />,
          },
          {
            path: 'drafts/:id',
            element: <DraftDetail />,
          },
          {
            path: 'drafts/:id/edit',
            element: <DraftEdit />,
          },
          {
            path: 'create-post-draft',
            element: <NewDraft />,
          },
        ],
      },
      {
        path: SPORTS_POOL_PATHS.ROOT,
        defaultPathIf: ROUTE_PERMISSIONS.SPORTS_POOL,
        children: [
          {
            index: true,
            element: (
              <Navigate
                to={SPORTS_POOL_PATHS.COMPETITIONS}
                replace
              />
            ),
          },
          {
            path: SPORTS_POOL_PATHS.COMPETITIONS,
            children: [
              {
                index: true,
                // TODO: Re-enable permissions guard once backend returns VIEW_SPORTS_POOL
                element: <SportsPoolCompetitions />,
              },
              {
                path: ':competitionId',
                // TODO: Re-enable permissions guard once backend returns VIEW_SPORTS_POOL
                element: <SportsPoolCompetitionDetail />,
              },
              {
                path: ':competitionId/rules',
                // TODO: Re-enable permissions guard once backend returns VIEW_SPORTS_POOL
                element: <SportsPoolCompetitionDetail />,
              },
              {
                path: ':competitionId/ranking',
                element: <SportsPoolCompetitionDetail />,
              },
              {
                path: `:competitionId/${SPORTS_POOL_PATHS.PODIUM}`,
                element: <SportsPoolPodiumPage />,
              },
            ],
          },
        ],
      },
    ],
  };

  dashboardRoutes.children.push(
    getDefaultRoute(dashboardRoutes, permissions, user),
  );

  const authenticationRoutes = {
    path: 'authentication',
    children: [
      {
        path: 'login',
        element: (
          <GuestGuard>
            <Login />
          </GuestGuard>
        ),
      },
      {
        path: 'otp',
        element: (
          <GuestGuard>
            <LoginOTP />
          </GuestGuard>
        ),
      },
      {
        path: 'update-password',
        element: (
          <GuestGuard>
            <UpdatePassword />
          </GuestGuard>
        ),
      },
    ],
  };

  const registrationRoutes = [
    {
      path: 'register-user',
      element: (
        <GuestGuard>
          <RegisterUser />
        </GuestGuard>
      ),
    },
    {
      path: 'join-by-link',
      element: (
        <GuestGuard>
          <JoinByLink />
        </GuestGuard>
      ),
    },
    {
      path: 'restore-password',
      element: (
        <GuestGuard>
          <RestorePassword />
        </GuestGuard>
      ),
    },
    {
      path: 'blank.html',
      element: <></>,
    },
  ];

  const externalReviewRoutes = {
    path: 'performance/:id/external',
    element: (
      <GuestGuard>
        <PerformanceExternalReview />
      </GuestGuard>
    ),
  };

  const timeoffUpdateRequest = {
    path: 'time-off-update-request',
    element: <UpdateRequestByMail />,
  };

  const communityRoutes = {
    path: 'new',
    element: (
      <GuestGuard>
        <Community />
      </GuestGuard>
    ),
  };

  const videoCall = {
    path: 'call/:callId/:providerCallId',
    element: (
      <CommunityFeatureGuard
        requiredCommunityFeature={CommunityFeature.VIEW_CALL}
      >
        <SocketProvider>
          <VideoCall />
        </SocketProvider>
      </CommunityFeatureGuard>
    ),
  };

  const incomingCallPopup = {
    path: 'incoming-call',
    element: (
      <CommunityFeatureGuard
        requiredCommunityFeature={CommunityFeature.VIEW_CALL}
      >
        <SocketProvider>
          <IncomingCallPopupPage />
        </SocketProvider>
      </CommunityFeatureGuard>
    ),
  };

  const orgChartMobile = {
    path: 'org-chart-mobile/:accessToken/:id',
    element: (
      <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.ORG_CHART}>
        <OrgChart isMobile />
      </PermissionsGuard>
    ),
  };

  const sportsPoolMobile = {
    path: `${SPORTS_POOL_PATHS.MOBILE_ROOT}/:accessToken`,
    element: <SportsPoolMobilePreloader />,
    children: [
      {
        index: true,
        element: <SportsPoolMobileIndexRedirect />,
      },
      {
        path: SPORTS_POOL_PATHS.COMPETITIONS,
        children: [
          {
            index: true,
            element: <SportsPoolCompetitions />,
          },
          {
            path: ':competitionId',
            element: <SportsPoolCompetitionDetail />,
          },
          {
            path: ':competitionId/rules',
            element: <SportsPoolCompetitionDetail />,
          },
          {
            path: ':competitionId/ranking',
            element: <SportsPoolCompetitionDetail />,
          },
          {
            path: `:competitionId/${SPORTS_POOL_PATHS.PODIUM}`,
            element: <SportsPoolPodiumPage />,
          },
        ],
      },
      {
        path: '*',
        element: (
          <Navigate
            to={SPORTS_POOL_PATHS.COMPETITIONS}
            replace
          />
        ),
      },
    ],
  };

  const scormMobile = {
    path: '/scorm-courses-mobile/:accessToken',
    element: (
      <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.SCORMS}>
        <ScormFolders isMobile={true} />
      </PermissionsGuard>
    ),
  };

  const nemakRecognitionsMobileRoutes = {
    path: '/recognitions-nemak-mobile/:accessToken',
    element: (
      <PermissionsGuard
        requiredPermissions={ROUTE_PERMISSIONS.RECOGNITIONS_NEMAK}
      >
        <Recognitions isMobile={true} />
      </PermissionsGuard>
    ),
  };

  const lacomerDocumentsMobileRoutes = {
    path: '/documents-lacomer-mobile/:refreshToken',
    element: (
      <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.DOCUMENTS}>
        <LaComerDocuments isMobileWebView={true} />
      </PermissionsGuard>
    ),
  };

  const banBajioMobileRoutes = {
    path: '/requests-banbajio-mobile/:refreshToken',
    element: (
      <PermissionsGuard requiredPermissions={ROUTE_PERMISSIONS.FEED}>
        <BanBajioCustomErrorBoundary>
          <BanBajioRequests isMobile={true} />
        </BanBajioCustomErrorBoundary>
      </PermissionsGuard>
    ),
  };

  const payrollMobilityAdoMobileRoutes = {
    path: '/payroll-mobility-ado-mobile/:refreshToken',
    element: (
      <PermissionsGuard
        requiredPermissions={ROUTE_PERMISSIONS.PAYROLL_MOBILITY_ADO}
      >
        <PayrollMobilityAdoPage isMobile />
      </PermissionsGuard>
    ),
  };

  const errorRoutes = {
    path: '*',
    children: [
      {
        path: '*',
        element: (
          <Navigate
            to={'/'}
            replace
          />
        ),
      },
    ],
  };

  return [
    authenticationRoutes,
    communityRoutes,
    timeoffUpdateRequest,
    scormMobile,
    nemakRecognitionsMobileRoutes,
    orgChartMobile,
    sportsPoolMobile,
    videoCall,
    incomingCallPopup,
    ...registrationRoutes,
    externalReviewRoutes,
    dashboardRoutes,
    errorRoutes,
    lacomerDocumentsMobileRoutes,
    banBajioMobileRoutes,
    payrollMobilityAdoMobileRoutes,
  ];
};

export default routes;
