import React, { useState, useEffect, Suspense } from 'react';
import { GameProvider, useGame } from './context/GameContext';
import { Monitor, Smartphone, LayoutDashboard, Loader2, RefreshCw } from 'lucide-react';
// Lazy load components to reduce initial bundle size
const HostView = React.lazy(() => import('./components/HostView').then(module => ({ default: module.HostView })));
const PlayerView = React.lazy(() => import('./components/PlayerView').then(module => ({ default: module.PlayerView })));
const SpectatorView = React.lazy(() => import('./components/SpectatorView').then(module => ({ default: module.SpectatorView })));
// Inner Component to access Context
const AppContent: React.FC = () => {
const { setIsHost, isSyncing, isHost } = useGame();
const [view, setView] = useState<'HOST' | 'PLAYER' | 'SPECTATOR'>('SPECTATOR');
// Simple hash routing for demo purposes
useEffect(() => {
const handleHashChange = () => {
const hash = window.location.hash;
if (hash === '#host') {
setView('HOST');
setIsHost(true); // Promote this session to Host Authority
}
else if (hash === '#player') {
setView('PLAYER');
setIsHost(false);
}
else {
setView('SPECTATOR');
setIsHost(false);
}
};
handleHashChange();
window.addEventListener('hashchange', handleHashChange);
return () => window.removeEventListener('hashchange', handleHashChange);
}, [setIsHost]);
const navigate = (newView: 'HOST' | 'PLAYER' | 'SPECTATOR') => {
setView(newView);
window.location.hash = newView.toLowerCase();
};
const renderView = () => {
switch (view) {
case 'HOST': return
Loading Quiz Module...