import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { QueryClientProvider } from '@tanstack/react-query';
import { queryClientInstance } from '@/lib/query-client';
import { Toaster } from '@/components/ui/sonner';
import { AuthProvider } from '@/lib/AuthContext';
import AppLayout from '@/components/AppLayout';
import Dashboard from '@/pages/Dashboard';
import Products from '@/pages/Products';
import Marketplaces from '@/pages/Marketplaces';
import Orders from '@/pages/Orders';
import Settings from '@/pages/Settings';
import CreateProduct from '@/pages/CreateProduct';
import CostCalculator from '@/pages/CostCalculator';
import Shipping from '@/pages/Shipping';
import EtsyCallback from '@/pages/EtsyCallback';
import Assistant from '@/pages/Assistant';

function App() {
  return (
    <AuthProvider>
      <QueryClientProvider client={queryClientInstance}>
        <Router>
          <Routes>
            <Route path="/login" element={<Navigate to="/" replace />} />
            <Route path="/etsy/callback" element={<EtsyCallback />} />
            <Route element={<AppLayout />}>
              <Route path="/" element={<Dashboard />} />
              <Route path="/products" element={<Products />} />
              <Route path="/marketplaces" element={<Marketplaces />} />
              <Route path="/orders" element={<Orders />} />
              <Route path="/settings" element={<Settings />} />
              <Route path="/products/create" element={<CreateProduct />} />
              <Route path="/calculator" element={<CostCalculator />} />
              <Route path="/shipping" element={<Shipping />} />
              <Route path="/assistant" element={<Assistant />} />
            </Route>
            <Route path="*" element={<Navigate to="/" replace />} />
          </Routes>
        </Router>
        <Toaster />
      </QueryClientProvider>
    </AuthProvider>
  );
}

export default App;
