import { createBrowserRouter } from 'react-router-dom'
import { lazy, Suspense } from 'react'
import { AppLayout, ProtectedRoute } from '@/components/layout'
import { RouteError } from '@/components/common/RouteError'
import { PageLoader } from '@/components/common/PageLoader'
import {
LoginPage,
RegisterPage,
} from '@/pages'
// Public pages
const SharedSessionPage = lazy(() => import('@/pages/SharedSessionPage'))
const SurveyPage = lazy(() => import('@/pages/SurveyPage'))
const SurveyThankYouPage = lazy(() => import('@/pages/SurveyThankYouPage'))
// Standalone auth pages
const VerifyEmailPage = lazy(() => import('@/pages/VerifyEmailPage'))
const ChangePasswordPage = lazy(() => import('@/pages/ChangePasswordPage'))
const ForgotPasswordPage = lazy(() => import('@/pages/ForgotPasswordPage'))
const ResetPasswordPage = lazy(() => import('@/pages/ResetPasswordPage'))
// Lazy load heavy pages for code splitting
const QuickStartPage = lazy(() => import('@/pages/QuickStartPage'))
const TreeLibraryPage = lazy(() => import('@/pages/TreeLibraryPage'))
const MyTreesPage = lazy(() => import('@/pages/MyTreesPage'))
const TreeNavigationPage = lazy(() => import('@/pages/TreeNavigationPage'))
const TreeEditorPage = lazy(() => import('@/pages/TreeEditorPage'))
const ProceduralEditorPage = lazy(() => import('@/pages/ProceduralEditorPage'))
const ProceduralNavigationPage = lazy(() => import('@/pages/ProceduralNavigationPage'))
const MaintenanceFlowDetailPage = lazy(() => import('@/pages/MaintenanceFlowDetailPage'))
const BatchStatusPage = lazy(() => import('@/pages/BatchStatusPage'))
const SessionHistoryPage = lazy(() => import('@/pages/SessionHistoryPage'))
const SessionDetailPage = lazy(() => import('@/pages/SessionDetailPage'))
const MySharesPage = lazy(() => import('@/pages/MySharesPage'))
const TeamAnalyticsPage = lazy(() => import('@/pages/TeamAnalyticsPage'))
const MyAnalyticsPage = lazy(() => import('@/pages/MyAnalyticsPage'))
const FeedbackPage = lazy(() => import('@/pages/FeedbackPage'))
const StepLibraryPage = lazy(() => import('@/pages/StepLibraryPage'))
const AIChatBuilderPage = lazy(() => import('@/pages/AIChatBuilderPage'))
const AssistantChatPage = lazy(() => import('@/pages/AssistantChatPage'))
const GuidesHubPage = lazy(() => import('@/pages/GuidesHubPage'))
const GuideDetailPage = lazy(() => import('@/pages/GuideDetailPage'))
const AccountSettingsPage = lazy(() => import('@/pages/AccountSettingsPage'))
// Admin pages
const AdminLayout = lazy(() => import('@/components/admin/AdminLayout'))
const AdminDashboardPage = lazy(() => import('@/pages/admin/DashboardPage'))
const AdminUsersPage = lazy(() => import('@/pages/admin/UsersPage'))
const AdminUserDetailPage = lazy(() => import('@/pages/admin/UserDetailPage'))
const AdminInviteCodesPage = lazy(() => import('@/pages/admin/InviteCodesPage'))
const AdminAuditLogsPage = lazy(() => import('@/pages/admin/AuditLogsPage'))
const AdminPlanLimitsPage = lazy(() => import('@/pages/admin/PlanLimitsPage'))
const AdminFeatureFlagsPage = lazy(() => import('@/pages/admin/FeatureFlagsPage'))
const AdminSettingsPage = lazy(() => import('@/pages/admin/SettingsPage'))
const AdminGlobalCategoriesPage = lazy(() => import('@/pages/admin/GlobalCategoriesPage'))
const AdminSurveyInvitesPage = lazy(() => import('@/pages/admin/SurveyInvitesPage'))
const AdminSurveyResponsesPage = lazy(() => import('@/pages/admin/SurveyResponsesPage'))
// Account pages
const AccountLayout = lazy(() => import('@/components/account/AccountLayout'))
const ProfileSettingsPage = lazy(() => import('@/pages/account/ProfileSettingsPage'))
const TeamCategoriesPage = lazy(() => import('@/pages/account/TeamCategoriesPage'))
const TargetListsPage = lazy(() => import('@/pages/account/TargetListsPage'))
const ChatRetentionSettingsPage = lazy(() => import('@/pages/account/ChatRetentionSettingsPage'))
export const router = createBrowserRouter([
{
path: '/login',
element: ,
errorElement: ,
},
{
path: '/register',
element: ,
errorElement: ,
},
{
path: '/forgot-password',
element: (
}>
),
errorElement: ,
},
{
path: '/reset-password',
element: (
}>
),
errorElement: ,
},
{
path: '/verify-email',
element: (
}>
),
errorElement: ,
},
{
path: '/survey',
element: (
}>
),
errorElement: ,
},
{
path: '/survey/thank-you',
element: (
}>
),
errorElement: ,
},
{
path: '/share/:shareToken',
element: (
}>
),
errorElement: ,
},
{
path: '/change-password',
element: (
}>
),
errorElement: ,
},
{
path: '/',
element: (
),
errorElement: ,
children: [
{
index: true,
element: (
}>
),
},
{
path: 'trees',
element: (
}>
),
},
{
path: 'my-trees',
element: (
}>
),
},
{
path: 'trees/new',
element: (
}>
),
},
{
path: 'trees/:id/edit',
element: (
}>
),
},
{
path: 'flows/new',
element: (
}>
),
},
{
path: 'flows/:id/edit',
element: (
}>
),
},
{
path: 'flows/:id/navigate',
element: (
}>
),
},
{
path: 'flows/:id/maintenance',
element: (
}>
),
},
{
path: 'flows/:id/batches/:batchId',
element: (
}>
),
},
{
path: 'trees/:id/navigate',
element: (
}>
),
},
{
path: 'sessions',
element: (
}>
),
},
{
path: 'sessions/:id',
element: (
}>
),
},
{
path: 'shares',
element: (
}>
),
},
{
path: 'analytics',
element: (
}>
),
},
{
path: 'analytics/me',
element: (
}>
),
},
{
path: 'feedback',
element: (
}>
),
},
{
path: 'step-library',
element: (
}>
),
},
{
path: 'ai/chat',
element: (
}>
),
},
{
path: 'assistant',
element: (
}>
),
},
{
path: 'guides',
element: (
}>
),
},
{
path: 'guides/:slug',
element: (
}>
),
},
// Admin routes
{
path: 'admin',
element: (
}>
),
children: [
{
index: true,
element: (
}>
),
},
{
path: 'users',
element: (
}>
),
},
{
path: 'users/:userId',
element: (
}>
),
},
{
path: 'invite-codes',
element: (
}>
),
},
{
path: 'audit-logs',
element: (
}>
),
},
{
path: 'plan-limits',
element: (
}>
),
},
{
path: 'feature-flags',
element: (
}>
),
},
{
path: 'settings',
element: (
}>
),
},
{
path: 'categories',
element: (
}>
),
},
{
path: 'survey-invites',
element: (
}>
),
},
{
path: 'survey-responses',
element: (
}>
),
},
],
},
// Account routes
{
path: 'account',
element: (
}>
),
children: [
{
index: true,
element: (
}>
),
},
{
path: 'profile',
element: (
}>
),
},
{
path: 'categories',
element: (
}>
),
},
{
path: 'chat-retention',
element: (
}>
),
},
{
path: 'target-lists',
element: (
}>
),
},
],
},
],
},
])
export default router