import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import Header from './Header';
import LoginPage from './LoginPage';
import ProductList from './ProductList';
import ProductDetail from './ProductDetail';
import CartPage from './CartPage';
import UserProfile from './UserProfile';
import AdminLayout from './AdminLayout';
import AdminRoute from './AdminRoute';
import ProductManagement from './ProductManagement';
import ProductForm from './ProductForm';
import SellerManagement from './SellerManagement';
import SellerForm from './SellerForm';
import CategoryManagement from './CategoryManagement';
import CategoryForm from './CategoryForm';
import { CartProvider } from './CartContext';
import { AuthProvider } from './AuthContext';

function App() {
  return (
    <Router>
      <AuthProvider>
        <CartProvider>
          <Routes>
            <Route path="/*" element={
              <>
                <Header />
                <main>
                  <Routes>
                    <Route path="/" element={<ProductList />} />
                    <Route path="/product/:id" element={<ProductDetail />} />
                    <Route path="/cart" element={<CartPage />} />
                    <Route path="/login" element={<LoginPage />} />
                    <Route path="/profile" element={<UserProfile />} />
                  </Routes>
                </main>
              </>
            } />
            <Route path="/admin/*" element={<AdminRoute />}>
                <Route path="products" element={<AdminLayout children={<ProductManagement />} />} />
                <Route path="products/create" element={<AdminLayout children={<ProductForm />} />} />
                <Route path="products/edit/:id" element={<AdminLayout children={<ProductForm />} />} />
                <Route path="categories" element={<AdminLayout children={<CategoryManagement />} />} />
                <Route path="categories/create" element={<AdminLayout children={<CategoryForm />} />} />
                <Route path="categories/edit/:id" element={<AdminLayout children={<CategoryForm />} />} />
                <Route path="sellers" element={<AdminLayout children={<SellerManagement />} />} />
                <Route path="sellers/create" element={<AdminLayout children={<SellerForm />} />} />
                <Route path="sellers/edit/:id" element={<AdminLayout children={<SellerForm />} />} />
            </Route>
          </Routes>
        </CartProvider>
      </AuthProvider>
    </Router>
  )
}

export default App;