import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import { AuthProvider } from "./auth/AuthContext";
import { RequireAdmin } from "./auth/RequireAdmin";
import { RequireAuth } from "./auth/RequireAuth";
import { AppShell } from "./components/layout/AppShell";
import { DataProvider } from "./data/DataContext";
import { I18nProvider } from "./i18n/I18nContext";
import { ThemeProvider } from "./theme/ThemeContext";
import { AdminUsersPage } from "./pages/AdminUsersPage";
import { BrandsPage } from "./pages/BrandsPage";
import { CrewPage } from "./pages/CrewPage";
import { JobDetailPage } from "./pages/JobDetailPage";
import { InsightsPage } from "./pages/InsightsPage";
import { InvitePage } from "./pages/InvitePage";
import { JobsPage } from "./pages/JobsPage";
import { ForgotPasswordPage } from "./pages/ForgotPasswordPage";
import { LoginPage } from "./pages/LoginPage";
import { OutboxDetailPage } from "./pages/OutboxDetailPage";
import { OutboxPage } from "./pages/OutboxPage";
import { ProfilePage } from "./pages/ProfilePage";
import { ResetPasswordPage } from "./pages/ResetPasswordPage";
import { ScoutPage } from "./pages/ScoutPage";
import { SettingsPage } from "./pages/SettingsPage";
import { PlanCheckoutPage } from "./pages/PlanCheckoutPage";
import { PlansPage } from "./pages/PlansPage";
import { UsagePage } from "./pages/UsagePage";
import { StudioPage } from "./pages/StudioPage";
import { VerifyEmailPage } from "./pages/VerifyEmailPage";
import { WizardPage } from "./pages/studio/WizardPage";
import { TodayPage } from "./pages/TodayPage";

export default function App() {
  return (
    <ThemeProvider>
      <I18nProvider>
        <DataProvider>
          <AuthProvider>
            <BrowserRouter>
            <Routes>
              <Route path="/login" element={<LoginPage />} />
              <Route path="/forgot-password" element={<ForgotPasswordPage />} />
              <Route path="/reset-password" element={<ResetPasswordPage />} />
              <Route path="/verify-email" element={<VerifyEmailPage />} />
              <Route
                path="/app"
                element={
                  <RequireAuth>
                    <AppShell />
                  </RequireAuth>
                }
              >
                <Route index element={<Navigate to="today" replace />} />
                <Route path="today" element={<TodayPage />} />
                <Route path="crew" element={<CrewPage />} />
                <Route path="studio" element={<StudioPage />} />
                <Route path="studio/new" element={<WizardPage />} />
                <Route path="studio/:playId" element={<WizardPage />} />
                <Route path="outbox" element={<OutboxPage />} />
                <Route path="outbox/:id" element={<OutboxDetailPage />} />
                <Route path="scout" element={<ScoutPage />} />
                <Route path="brands" element={<BrandsPage />} />
                <Route path="settings" element={<SettingsPage />} />
                <Route path="profile" element={<ProfilePage />} />
                <Route path="invite" element={<InvitePage />} />
                <Route
                  path="users"
                  element={
                    <RequireAdmin>
                      <AdminUsersPage />
                    </RequireAdmin>
                  }
                />
                <Route path="usage" element={<UsagePage />} />
                <Route path="usage/plans" element={<PlansPage />} />
                <Route path="usage/checkout" element={<PlanCheckoutPage />} />
                <Route path="jobs" element={<JobsPage />} />
                <Route path="jobs/:id" element={<JobDetailPage />} />
                <Route path="insights" element={<InsightsPage />} />
              </Route>
              <Route path="/" element={<Navigate to="/app/today" replace />} />
              <Route path="*" element={<Navigate to="/app/today" replace />} />
            </Routes>
            </BrowserRouter>
          </AuthProvider>
        </DataProvider>
      </I18nProvider>
    </ThemeProvider>
  );
}
