import './App.css';
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import { AuthProvider } from './context/AuthContext';
import ProtectedRoute from './components/ProtectedRoute';
import Login from './components/Login';
import RoleRedirect from './components/RoleRedirect';
import DefektTrackApp from './components/DefektTrackApp';
import AssetDetail from './components/AssetDetail';
import AdminPanel from './components/AdminPanel';
import FilialleiterDashboard from './components/FilialleiterDashboard';
import FirmenleiterDashboard from './components/FirmenleiterDashboard';

function App() {
  return (
    <BrowserRouter>
      <AuthProvider>
        <Routes>
          <Route path="/login" element={<Login />} />

          <Route
            path="/"
            element={
              <ProtectedRoute>
                <RoleRedirect />
              </ProtectedRoute>
            }
          />

          <Route
            path="/tracker"
            element={
              <ProtectedRoute>
                <DefektTrackApp />
              </ProtectedRoute>
            }
          />

          <Route
            path="/asset/:id"
            element={
              <ProtectedRoute>
                <AssetDetail />
              </ProtectedRoute>
            }
          />

          <Route
            path="/admin"
            element={
              <ProtectedRoute>
                <AdminPanel />
              </ProtectedRoute>
            }
          />

          <Route
            path="/filialleiter"
            element={
              <ProtectedRoute>
                <FilialleiterDashboard />
              </ProtectedRoute>
            }
          />

          <Route
            path="/firmenleiter"
            element={
              <ProtectedRoute>
                <FirmenleiterDashboard />
              </ProtectedRoute>
            }
          />

          <Route path="*" element={<Navigate to="/" replace />} />
        </Routes>
      </AuthProvider>
    </BrowserRouter>
  );
}

export default App;
