import { Routes, Route } from 'react-router-dom';
import { NotificationProvider } from './contexts/NotificationContext';
import { AuthProvider } from './contexts/AuthContext';
import { PermissionProvider } from './contexts/PermissionContext';
import ErrorBoundary from './components/shared/ErrorBoundary';
import ProtectedRoute from './components/auth/ProtectedRoute';
import LoginCallback from './components/auth/LoginCallback';
import Login from './pages/Login';
import Dashboard from './pages/Dashboard';
import Profile from './pages/Profile';
import Settings from './pages/Settings';
import Einsaetze from './pages/Einsaetze';
import EinsatzDetail from './pages/EinsatzDetail';
import Fahrzeuge from './pages/Fahrzeuge';
import FahrzeugDetail from './pages/FahrzeugDetail';
import FahrzeugForm from './pages/FahrzeugForm';
import FahrzeugBuchungen from './pages/FahrzeugBuchungen';
import Ausruestung from './pages/Ausruestung';
import AusruestungForm from './pages/AusruestungForm';
import AusruestungDetail from './pages/AusruestungDetail';
import Atemschutz from './pages/Atemschutz';
import Mitglieder from './pages/Mitglieder';
import MitgliedDetail from './pages/MitgliedDetail';
import Kalender from './pages/Kalender';
import UebungDetail from './pages/UebungDetail';
import Veranstaltungen from './pages/Veranstaltungen';
import VeranstaltungKategorien from './pages/VeranstaltungKategorien';
import Wissen from './pages/Wissen';
import Bestellungen from './pages/Bestellungen';
import BestellungDetail from './pages/BestellungDetail';
import Shop from './pages/Shop';
import AdminDashboard from './pages/AdminDashboard';
import AdminSettings from './pages/AdminSettings';
import NotFound from './pages/NotFound';

function App() {
  return (
    <ErrorBoundary>
      <NotificationProvider>
        <AuthProvider>
          <PermissionProvider>
          <Routes>
            <Route path="/" element={<Login />} />
            <Route path="/login" element={<Login />} />
            <Route path="/auth/callback" element={<LoginCallback />} />
            <Route
              path="/dashboard"
              element={
                <ProtectedRoute>
                  <Dashboard />
                </ProtectedRoute>
              }
            />
            <Route
              path="/profile"
              element={
                <ProtectedRoute>
                  <Profile />
                </ProtectedRoute>
              }
            />
            <Route
              path="/settings"
              element={
                <ProtectedRoute>
                  <Settings />
                </ProtectedRoute>
              }
            />
            <Route
              path="/einsaetze"
              element={
                <ProtectedRoute>
                  <Einsaetze />
                </ProtectedRoute>
              }
            />
            <Route
              path="/einsaetze/:id"
              element={
                <ProtectedRoute>
                  <EinsatzDetail />
                </ProtectedRoute>
              }
            />
            <Route
              path="/fahrzeuge"
              element={
                <ProtectedRoute>
                  <Fahrzeuge />
                </ProtectedRoute>
              }
            />
            <Route
              path="/fahrzeuge/neu"
              element={
                <ProtectedRoute>
                  <FahrzeugForm />
                </ProtectedRoute>
              }
            />
            <Route
              path="/fahrzeuge/:id/bearbeiten"
              element={
                <ProtectedRoute>
                  <FahrzeugForm />
                </ProtectedRoute>
              }
            />
            <Route
              path="/fahrzeuge/:id"
              element={
                <ProtectedRoute>
                  <FahrzeugDetail />
                </ProtectedRoute>
              }
            />
            <Route
              path="/ausruestung"
              element={
                <ProtectedRoute>
                  <Ausruestung />
                </ProtectedRoute>
              }
            />
            <Route
              path="/ausruestung/neu"
              element={
                <ProtectedRoute>
                  <AusruestungForm />
                </ProtectedRoute>
              }
            />
            <Route
              path="/ausruestung/:id/bearbeiten"
              element={
                <ProtectedRoute>
                  <AusruestungForm />
                </ProtectedRoute>
              }
            />
            <Route
              path="/ausruestung/:id"
              element={
                <ProtectedRoute>
                  <AusruestungDetail />
                </ProtectedRoute>
              }
            />
            <Route
              path="/atemschutz"
              element={
                <ProtectedRoute>
                  <Atemschutz />
                </ProtectedRoute>
              }
            />
            <Route
              path="/mitglieder"
              element={
                <ProtectedRoute>
                  <Mitglieder />
                </ProtectedRoute>
              }
            />
            <Route
              path="/mitglieder/:userId"
              element={
                <ProtectedRoute>
                  <MitgliedDetail />
                </ProtectedRoute>
              }
            />
            <Route
              path="/kalender"
              element={
                <ProtectedRoute>
                  <Kalender />
                </ProtectedRoute>
              }
            />
            <Route
              path="/training/:id"
              element={
                <ProtectedRoute>
                  <UebungDetail />
                </ProtectedRoute>
              }
            />
            <Route
              path="/veranstaltungen"
              element={
                <ProtectedRoute>
                  <Veranstaltungen />
                </ProtectedRoute>
              }
            />
            <Route
              path="/veranstaltungen/kategorien"
              element={
                <ProtectedRoute>
                  <VeranstaltungKategorien />
                </ProtectedRoute>
              }
            />
            <Route
              path="/fahrzeugbuchungen"
              element={
                <ProtectedRoute>
                  <FahrzeugBuchungen />
                </ProtectedRoute>
              }
            />
            <Route
              path="/wissen"
              element={
                <ProtectedRoute>
                  <Wissen />
                </ProtectedRoute>
              }
            />
            <Route
              path="/bestellungen"
              element={
                <ProtectedRoute>
                  <Bestellungen />
                </ProtectedRoute>
              }
            />
            <Route
              path="/bestellungen/:id"
              element={
                <ProtectedRoute>
                  <BestellungDetail />
                </ProtectedRoute>
              }
            />
            <Route
              path="/shop"
              element={
                <ProtectedRoute>
                  <Shop />
                </ProtectedRoute>
              }
            />
            <Route
              path="/admin"
              element={
                <ProtectedRoute>
                  <AdminDashboard />
                </ProtectedRoute>
              }
            />
            <Route
              path="/admin/settings"
              element={
                <ProtectedRoute>
                  <AdminSettings />
                </ProtectedRoute>
              }
            />
            <Route path="*" element={<NotFound />} />
          </Routes>
          </PermissionProvider>
        </AuthProvider>
      </NotificationProvider>
    </ErrorBoundary>
  );
}

export default App;
