import { BrowserRouter, Route, Routes } from "react-router-dom";
import { I18nProvider } from "./i18n";
import { adminUiPrefix } from "./adminPaths";
import { AdminRouterModeProvider } from "./adminRouterMode";
import { AdminLayout } from "./layouts/AdminLayout";
import { AdminLogin } from "./pages/admin/AdminLogin";
import { AdminDashboard } from "./pages/admin/AdminDashboard";
import { AdminResources } from "./pages/admin/AdminResources";
import { AdminResourceForm } from "./pages/admin/AdminResourceForm";
import { AdminSearchLogs } from "./pages/admin/AdminSearchLogs";

function NotFound() {
  return (
    <div className="flex min-h-screen items-center justify-center bg-black text-neutral-400">
      <p className="text-sm">404</p>
    </div>
  );
}

/**
 * Admin-only bundle: mount under `BrowserRouter basename={adminUiPrefix}` with **relative** route paths
 * so React Router does not choke on a single long absolute path segment.
 */
export default function AppAdminOnly() {
  const b = adminUiPrefix;
  return (
    <I18nProvider>
      <AdminRouterModeProvider value="basename">
        <BrowserRouter basename={b}>
          <Routes>
            <Route path="login" element={<AdminLogin />} />
            <Route path="/" element={<AdminLayout />}>
              <Route index element={<AdminDashboard />} />
              <Route path="resources" element={<AdminResources />} />
              <Route path="resources/new" element={<AdminResourceForm />} />
              <Route path="resources/:id" element={<AdminResourceForm />} />
              <Route path="search-logs" element={<AdminSearchLogs />} />
            </Route>
            <Route path="*" element={<NotFound />} />
          </Routes>
        </BrowserRouter>
      </AdminRouterModeProvider>
    </I18nProvider>
  );
}
