/**
 * Redirect Intelligence v2 - Main App Component
 * 
 * Modern Chakra UI application with comprehensive redirect analysis
 */

import React from 'react';
import { ChakraProvider, Box } from '@chakra-ui/react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

// Theme and layout
import { theme } from './theme/theme';
import { Layout } from './components/Layout/Layout';

// Pages
import { HomePage } from './pages/HomePage';
import { TrackingPage } from './pages/TrackingPage';
import { AnalysisPage } from './pages/AnalysisPage';
import { DashboardPage } from './pages/DashboardPage';
import { LoginPage } from './pages/LoginPage';
import { RegisterPage } from './pages/RegisterPage';
import { CheckDetailPage } from './pages/CheckDetailPage';

// Context providers
import { AuthProvider } from './contexts/AuthContext';

// Create React Query client
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      retry: 2,
      refetchOnWindowFocus: false,
      staleTime: 5 * 60 * 1000, // 5 minutes
    },
  },
});

function App() {
  return (
    <ChakraProvider theme={theme}>
      <QueryClientProvider client={queryClient}>
        <AuthProvider>
          <Router>
            <Layout>
              <Routes>
                {/* Public routes */}
                <Route path="/" element={<HomePage />} />
                <Route path="/track" element={<TrackingPage />} />
                <Route path="/analysis" element={<AnalysisPage />} />
                <Route path="/login" element={<LoginPage />} />
                <Route path="/register" element={<RegisterPage />} />
                
                {/* Protected routes */}
                <Route path="/dashboard" element={<DashboardPage />} />
                <Route path="/check/:checkId" element={<CheckDetailPage />} />
                
                {/* Legacy routes for backward compatibility */}
                <Route path="/api/docs" element={<div>API Documentation (Legacy)</div>} />
              </Routes>
            </Layout>
          </Router>
          
          {/* React Query DevTools (development only) */}
          {process.env.NODE_ENV === 'development' && (
            <ReactQueryDevtools initialIsOpen={false} />
          )}
        </AuthProvider>
      </QueryClientProvider>
    </ChakraProvider>
  );
}

export default App;
