import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import Layout from './components/Layout';
import HomePage from './pages/HomePage';
import LoginPage from './pages/LoginPage';
import SignupPage from './pages/SignupPage';
import ReservationPage from './pages/ReservationPage';
import MyReservationPage from './pages/MyReservationPage';
import AdminLayout from './pages/admin/AdminLayout';
import AdminPage from './pages/admin/AdminPage';
import AdminReservationPage from './pages/admin/ReservationPage';
import AdminTimePage from './pages/admin/TimePage';
import AdminThemePage from './pages/admin/ThemePage';
import AdminWaitingPage from './pages/admin/WaitingPage';
import { AuthProvider } from './context/AuthContext';
import AdminRoute from './components/AdminRoute';
import ReservationStep1Page from './pages/v2/ReservationStep1Page';
import ReservationStep2Page from './pages/v2/ReservationStep2Page';
import ReservationSuccessPage from './pages/v2/ReservationSuccessPage';
import MyReservationPageV2 from './pages/v2/MyReservationPageV2';
import ReservationStep1PageV21 from './pages/v2/ReservationStep1PageV21';
import ReservationStep2PageV21 from './pages/v2/ReservationStep2PageV21';
import ReservationSuccessPageV21 from './pages/v2/ReservationSuccessPageV21';
import HomePageV2 from './pages/v2/HomePageV2';
import LoginPageV2 from './pages/v2/LoginPageV2';
import SignupPageV2 from './pages/v2/SignupPageV2';
import ReservationFormPage from './pages/v2/ReservationFormPage';
import AdminThemeEditPage from './pages/admin/AdminThemeEditPage';
import AdminSchedulePage from './pages/admin/AdminSchedulePage';

const AdminRoutes = () => (
    <AdminLayout>
        <Routes>
            <Route path="/" element={<AdminPage />} />
            <Route path="/reservation" element={<AdminReservationPage />} />
            <Route path="/time" element={<AdminTimePage />} />
            <Route path="/theme" element={<AdminThemePage />} />
            <Route path="/theme/edit/:themeId" element={<AdminThemeEditPage />} />
            <Route path="/waiting" element={<AdminWaitingPage />} />
            <Route path="/schedule" element={<AdminSchedulePage />} />
        </Routes>
    </AdminLayout>
);

function App() {
    return (
        <AuthProvider>
            <Router>
                <Routes>
                    <Route path="/admin/*" element={
                        <AdminRoute>
                            <AdminRoutes />
                        </AdminRoute>
                    } />
                    <Route path="/*" element={
                        <Layout>
                            <Routes>
                                <Route path="/" element={<HomePage />} />
                                <Route path="/login" element={<LoginPage />} />
                                <Route path="/signup" element={<SignupPage />} />
                                <Route path="/reservation" element={<ReservationPage />} />
                                <Route path="/my-reservation" element={<MyReservationPage />} />
                                <Route path="/my-reservation/v2" element={<MyReservationPageV2 />} />

                                {/* V2 Pages */}
                                <Route path="/v2/home" element={<HomePageV2 />} />
                                <Route path="/v2/login" element={<LoginPageV2 />} />
                                <Route path="/v2/signup" element={<SignupPageV2 />} />

                                {/* V2 Reservation Flow */}
                                <Route path="/v2/reservation" element={<ReservationStep1Page />} />
                                <Route path="/v2/reservation/payment" element={<ReservationStep2Page />} />
                                <Route path="/v2/reservation/success" element={<ReservationSuccessPage />} />

                                {/* V2.1 Reservation Flow */}
                                <Route path="/v2-1/reservation" element={<ReservationStep1PageV21 />} />
                                <Route path="/v2/reservation/form" element={<ReservationFormPage />} />
                                <Route path="/v2-1/reservation/payment" element={<ReservationStep2PageV21 />} />
                                <Route path="/v2-1/reservation/success" element={<ReservationSuccessPageV21 />} />
                            </Routes>
                        </Layout>
                    } />
                </Routes>
            </Router>
        </AuthProvider>
    );
}

export default App;