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'
// Standalone auth pages
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 SessionHistoryPage = lazy(() => import('@/pages/SessionHistoryPage'))
const SessionDetailPage = lazy(() => import('@/pages/SessionDetailPage'))
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'))
// Account pages
const AccountLayout = lazy(() => import('@/components/account/AccountLayout'))
const TeamCategoriesPage = lazy(() => import('@/pages/account/TeamCategoriesPage'))
export const router = createBrowserRouter([
{
path: '/login',
element: ,
errorElement: ,
},
{
path: '/register',
element: ,
errorElement: ,
},
{
path: '/forgot-password',
element: (
}>
),
errorElement: ,
},
{
path: '/reset-password',
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: 'trees/:id/navigate',
element: (
}>
),
},
{
path: 'sessions',
element: (
}>
),
},
{
path: 'sessions/:id',
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: (
}>
),
},
],
},
// Account routes
{
path: 'account',
element: (
}>
),
children: [
{
index: true,
element: (
}>
),
},
{
path: 'categories',
element: (
}>
),
},
],
},
],
},
])
export default router