﻿import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { AuthProvider } from './context/AuthContext';
import Dashboard from './pages/Dashboard';
import Login from './pages/Login';
import Requests from './pages/Requests';
import Calendar from './pages/Calendar';
import Manager from './pages/Manager';
import ProtectedRoute from './components/ProtectedRoute';
import EmployeeDetails from './pages/EmployeeDetails';
import Collaborateur from './pages/Collaborateur';

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

                    {/* Routes protégées */}
                    <Route
                        path="/dashboard"
                        element={
                            <ProtectedRoute>
                                <Dashboard />
                            </ProtectedRoute>
                        }
                    />

                    <Route
                        path="/demandes"
                        element={
                            <ProtectedRoute allowedRoles={['Collaborateur', 'RH']}>
                                <Requests />
                            </ProtectedRoute>
                        }
                    />

                    <Route
                        path="/calendrier"
                        element={
                            <ProtectedRoute allowedRoles={['Collaborateur', 'Manager', 'RH']}>
                                <Calendar />
                            </ProtectedRoute>
                        }
                    />

                    <Route
                        path="/manager"
                        element={
                            <ProtectedRoute allowedRoles={['Manager']}>
                                <Manager />
                            </ProtectedRoute>
                        }
                    />

                    <Route
                        path="/collaborateur"
                        element={
                            <ProtectedRoute allowedRoles={['Collaborateur']}>
                                <Collaborateur />
                            </ProtectedRoute>
                        }
                    />

                    <Route
                        path="/employee/:id"
                        element={
                            <ProtectedRoute allowedRoles={['RH', 'Manager']}>
                                <EmployeeDetails />
                            </ProtectedRoute>
                        }
                    />

                    {/* Redirection par défaut */}
                    <Route path="/" element={<Navigate to="/dashboard" replace />} />
                </Routes>
            </Router>
        </AuthProvider>
    );
}

export default App;
