import React from 'react';
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import App from './App';
import MobileChartPage from './pages/MobileChartPage';
import RealtimeGaugeTestPage from './pages/RealtimeGaugeTestPage';
import { AppThemeProvider } from './contexts/ThemeContext';
import { ChartColorProvider } from './contexts/ChartColorContext';
import { IndicatorVisibilityProvider } from './contexts/IndicatorVisibilityContext';
import { IndicatorSettingsProvider } from './contexts/IndicatorSettingsContext';
import { IndicatorPopupProvider } from './contexts/IndicatorPopupContext';
import { AuthProvider } from './contexts/AuthContext';
import { UpbitDataProvider } from './contexts/UpbitDataContext';
import { UIThemeProvider } from './contexts/UIThemeContext';
import { AlertNotificationProvider } from './contexts/AlertNotificationContext';
import { NavigationProvider } from './contexts/NavigationContext';

/**
 * 앱 라우터
 * - 데스크톱: / (기본 앱)
 * - 모바일: /mobile/chart (모바일 차트 페이지)
 */
const AppRouter: React.FC = () => {
  return (
    <BrowserRouter>
      <AppThemeProvider>
        <ChartColorProvider>
          <IndicatorSettingsProvider>
            <IndicatorVisibilityProvider>
              <IndicatorPopupProvider>
                <AuthProvider>
                  <UIThemeProvider>
                    <UpbitDataProvider>
                      <AlertNotificationProvider>
                        <NavigationProvider>
                          <Routes>
                            {/* 데스크톱 버전 */}
                            <Route path="/" element={<App />} />
                            
                            {/* 모바일 차트 페이지 */}
                            <Route path="/mobile/chart" element={<MobileChartPage />} />
                            
                            {/* 실시간 게이지 테스트 페이지 */}
                            <Route path="/gauge-test" element={<RealtimeGaugeTestPage />} />
                            
                            {/* 기본 리다이렉트 */}
                            <Route path="*" element={<Navigate to="/" replace />} />
                          </Routes>
                        </NavigationProvider>
                      </AlertNotificationProvider>
                    </UpbitDataProvider>
                  </UIThemeProvider>
                </AuthProvider>
              </IndicatorPopupProvider>
            </IndicatorVisibilityProvider>
          </IndicatorSettingsProvider>
        </ChartColorProvider>
      </AppThemeProvider>
    </BrowserRouter>
  );
};

export default AppRouter;

