import { useEffect, useState } from 'react'; import { AnimatePresence, motion } from 'framer-motion'; import { GenerationProvider, useGeneration } from '@/context/GenerationContext'; import { AuthProvider, useAuth } from '@/context/AuthContext'; import { ProviderSelect, GenerationForm, GenerationProgress, GenerationComplete, ErrorDisplay, Login, LogoIcon } from '@/components'; import { checkHealth } from '@/utils/api'; import type { HealthStatus } from '@/types'; // Main App Content (uses context) function AppContent() { const { isAuthenticated, loading: authLoading, logout } = useAuth(); const { state, selectProvider, reset } = useGeneration(); const [healthStatus, setHealthStatus] = useState(null); const [healthError, setHealthError] = useState(null); // Check backend health on mount (must be called before any conditional returns) useEffect(() => { if (isAuthenticated) { checkHealth() .then(setHealthStatus) .catch((err) => setHealthError(err.message)); } }, [isAuthenticated]); // Show login if not authenticated if (authLoading) { return (

Loading...

); } if (!isAuthenticated) { return ; } // Render based on current step const renderContent = () => { switch (state.step) { case 'idle': return ( selectProvider(provider)} /> ); case 'configuring': return ( reset()} /> ); case 'generating_prompts': case 'generating_video': case 'processing': return ; case 'completed': return ; case 'error': return ; default: return ( selectProvider(provider)} /> ); } }; return (
{/* Header */}
{/* Logo */} {/* Status Indicator */}
{/* Provider Badge */} {state.provider && state.step !== 'idle' && ( {state.provider === 'kling' ? 'KIE API' : 'Replicate'} )} {/* Backend Status */}
{healthError ? 'Backend Offline' : healthStatus ? (healthStatus.is_dev_mode ? 'Dev Mode' : 'Production') : 'Connecting...'}
{/* Logout Button */}
{/* Main Content */}
{renderContent()}
{/* Footer */}

Powered by {' '} AdGenesis

); } // App Wrapper with Providers function App() { return ( ); } export default App;