//=======================================
// File: App.tsx
// Componete pagina principale dell'applicazione
// author: "villari.andrea@libero.it"
// version: "1.0.0 2026-07.14"
//=======================================

import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import { Toaster } from "@/components/ui/sonner";
import GuestRoute from "@/components/GuestRoute";
import Layout from "@/components/Layout";
import PagePlaceholder from "@/components/PagePlaceholder";
import ProtectedRoute from "@/components/ProtectedRoute";
import { AuthProvider } from "@/context/AuthContext";
import Dashboard from "@/pages/Dashboard";
import Login from "@/pages/Login";
import MieiCorsi from "@/pages/MieiCorsi";
import MioCorsoDettaglio from "@/pages/MioCorsoDettaglio";

export default function App() {
  return (
    <AuthProvider>
      <BrowserRouter>
        <Routes>
          <Route path="/login" element={<GuestRoute><Login /></GuestRoute>} />
          <Route element={<ProtectedRoute><Layout /></ProtectedRoute>}>
            <Route path="/dashboard" element={<Dashboard />} />
            <Route
              path="/i-miei-corsi"
              element={
                <ProtectedRoute roles={["Dipendente"]}>
                  <MieiCorsi />
                </ProtectedRoute>
              }
            />
            <Route
              path="/i-miei-corsi/:id"
              element={
                <ProtectedRoute roles={["Dipendente"]}>
                  <MioCorsoDettaglio />
                </ProtectedRoute>
              }
            />
            <Route
              path="/corsi"
              element={
                <ProtectedRoute roles={["Referente Academy"]}>
                  <PagePlaceholder
                    title="Catalogo corsi"
                    description="Gestione del catalogo corsi Academy."
                  />
                </ProtectedRoute>
              }
            />
            <Route
              path="/assegnazioni"
              element={
                <ProtectedRoute roles={["Referente Academy"]}>
                  <PagePlaceholder
                    title="Assegnazioni"
                    description="Gestione delle assegnazioni corsi ai dipendenti."
                  />
                </ProtectedRoute>
              }
            />
            <Route
              path="/dipendenti"
              element={
                <ProtectedRoute roles={["Referente Academy"]}>
                  <PagePlaceholder
                    title="Dipendenti"
                    description="Elenco dei dipendenti dell'organizzazione."
                  />
                </ProtectedRoute>
              }
            />
            <Route
              path="/statistiche"
              element={
                <ProtectedRoute roles={["Referente Academy"]}>
                  <PagePlaceholder
                    title="Statistiche"
                    description="Riepiloghi formativi per mese e categoria."
                  />
                </ProtectedRoute>
              }
            />
            <Route path="/" element={<Navigate to="/dashboard" replace />} />
            <Route path="*" element={<Navigate to="/dashboard" replace />} />
          </Route>
          <Route path="*" element={<Navigate to="/login" replace />} />
        </Routes>
        <Toaster />
      </BrowserRouter>
    </AuthProvider>
  );
}
