import { Routes, Route, Navigate } from "react-router-dom";

import ProtectedRoute from "./routes/ProtectedRoute";
import { AppLayout } from "./components/layout/AppLayout";

import Login from "./pages/auth/Login";
import Signup from "./pages/auth/Signup";
import ForgotPassword from "./pages/auth/ForgotPassword";
import ResetPassword from "./pages/auth/ResetPassword";

import Dashboard from "./pages/Dashboard";
import Documents from "./pages/Documents";
import DocumentWorkspace from "./pages/DocumentWorkspace";
import Knowledge from "./pages/Knowledge";
import KnowledgeDetail from "./pages/KnowledgeDetail";
import Search from "./pages/Search";
import Workflows from "./pages/Workflows";
import WorkflowDetail from "./pages/WorkflowDetail";
import Activity from "./pages/Activity";
import Settings from "./pages/Settings";

export default function App() {
    return (
        <Routes>
            {/* Standalone auth routes */}
            <Route path="/login" element={<Login />} />
            <Route path="/signup" element={<Signup />} />
            <Route path="/forgot-password" element={<ForgotPassword />} />
            <Route path="/reset-password" element={<ResetPassword />} />

            {/* Authenticated app shell */}
            <Route element={<ProtectedRoute />}>
                <Route element={<AppLayout />}>
                    <Route path="/" element={<Dashboard />} />
                    <Route path="/documents" element={<Documents />} />
                    <Route
                        path="/documents/:documentId/:workflowId"
                        element={<DocumentWorkspace />}
                    />
                    <Route path="/knowledge" element={<Knowledge />} />
                    <Route
                        path="/knowledge/:itemId"
                        element={<KnowledgeDetail />}
                    />
                    <Route path="/search" element={<Search />} />
                    <Route path="/workflows" element={<Workflows />} />
                    <Route
                        path="/workflows/:workflowId"
                        element={<WorkflowDetail />}
                    />
                    <Route path="/activity" element={<Activity />} />
                    <Route path="/settings" element={<Settings />} />
                </Route>
            </Route>

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