import React, { useEffect, lazy, Suspense } from 'react'; import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import { GlobalLoadingProvider } from './contexts/GlobalLoadingContext'; import { CookieConsentProvider } from './contexts/CookieConsentContext'; import { CurrencyProvider } from './contexts/CurrencyContext'; import OfflineIndicator from './components/common/OfflineIndicator'; import CookieConsentBanner from './components/common/CookieConsentBanner'; import AnalyticsLoader from './components/common/AnalyticsLoader'; import Loading from './components/common/Loading'; // Store import useAuthStore from './store/useAuthStore'; import useFavoritesStore from './store/useFavoritesStore'; // Layout Components import { LayoutMain } from './components/layout'; import AdminLayout from './pages/AdminLayout'; // Auth Components import { ProtectedRoute, AdminRoute } from './components/auth'; // Lazy load pages for code splitting const HomePage = lazy(() => import('./pages/HomePage')); const DashboardPage = lazy(() => import('./pages/customer/DashboardPage')); const RoomListPage = lazy(() => import('./pages/customer/RoomListPage')); const RoomDetailPage = lazy(() => import('./pages/customer/RoomDetailPage')); const SearchResultsPage = lazy(() => import('./pages/customer/SearchResultsPage')); const FavoritesPage = lazy(() => import('./pages/customer/FavoritesPage')); const MyBookingsPage = lazy(() => import('./pages/customer/MyBookingsPage')); const BookingPage = lazy(() => import('./pages/customer/BookingPage')); const BookingSuccessPage = lazy(() => import('./pages/customer/BookingSuccessPage')); const BookingDetailPage = lazy(() => import('./pages/customer/BookingDetailPage')); const DepositPaymentPage = lazy(() => import('./pages/customer/DepositPaymentPage')); const FullPaymentPage = lazy(() => import('./pages/customer/FullPaymentPage')); const PaymentConfirmationPage = lazy(() => import('./pages/customer/PaymentConfirmationPage')); const PaymentResultPage = lazy(() => import('./pages/customer/PaymentResultPage')); const InvoicePage = lazy(() => import('./pages/customer/InvoicePage')); const ProfilePage = lazy(() => import('./pages/customer/ProfilePage')); const AboutPage = lazy(() => import('./pages/AboutPage')); const ContactPage = lazy(() => import('./pages/ContactPage')); const LoginPage = lazy(() => import('./pages/auth/LoginPage')); const RegisterPage = lazy(() => import('./pages/auth/RegisterPage')); const ForgotPasswordPage = lazy(() => import('./pages/auth/ForgotPasswordPage')); const ResetPasswordPage = lazy(() => import('./pages/auth/ResetPasswordPage')); // Lazy load admin pages const AdminDashboardPage = lazy(() => import('./pages/admin/DashboardPage')); const UserManagementPage = lazy(() => import('./pages/admin/UserManagementPage')); const PageContentDashboardPage = lazy(() => import('./pages/admin/PageContentDashboard')); const AnalyticsDashboardPage = lazy(() => import('./pages/admin/AnalyticsDashboardPage')); const BusinessDashboardPage = lazy(() => import('./pages/admin/BusinessDashboardPage')); const SettingsPage = lazy(() => import('./pages/admin/SettingsPage')); const ReceptionDashboardPage = lazy(() => import('./pages/admin/ReceptionDashboardPage')); // Demo component for pages not yet created const DemoPage: React.FC<{ title: string }> = ({ title }) => (

{title}

This page is under development...

); function App() { // Use Zustand store const { isAuthenticated, userInfo, logout, initializeAuth } = useAuthStore(); const { fetchFavorites, syncGuestFavorites, loadGuestFavorites, } = useFavoritesStore(); // Initialize auth state when app loads useEffect(() => { initializeAuth(); }, [initializeAuth]); // Load favorites when authenticated or load guest favorites useEffect(() => { if (isAuthenticated) { // Sync guest favorites first, then fetch syncGuestFavorites().then(() => { fetchFavorites(); }); } else { // Load guest favorites from localStorage loadGuestFavorites(); } }, [ isAuthenticated, fetchFavorites, syncGuestFavorites, loadGuestFavorites, ]); // Handle logout const handleLogout = async () => { await logout(); }; return ( }> {/* Public Routes with Main Layout */} } > } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Protected Routes - Requires login */} } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Auth Routes (no layout) */} } /> } /> } /> } /> {/* Admin Routes - Only admin can access */} } > } /> } /> } /> } /> } /> } /> } /> } /> {/* 404 Route */} } /> ); } export default App;