import { Routes, Route } from 'react-router-dom';
import Navbar from './components/Navbar.jsx';
import Footer from './components/Footer.jsx';
import WhatsAppButton from './components/WhatsAppButton.jsx';
import { ProtectedRoute, AdminRoute, SuperAdminRoute } from './components/ProtectedRoute.jsx';

import Home from './pages/Home.jsx';
import Login from './pages/Login.jsx';
import Register from './pages/Register.jsx';
import ForgotPassword from './pages/ForgotPassword.jsx';
import Vendors from './pages/Vendors.jsx';
import VendorCourses from './pages/VendorCourses.jsx';
import CourseDetail from './pages/CourseDetail.jsx';
import ExamRunner from './pages/ExamRunner.jsx';
import Result from './pages/Result.jsx';
import Dashboard from './pages/Dashboard.jsx';
import Account from './pages/Account.jsx';
import Contribute from './pages/Contribute.jsx';
import SubmitQuestion from './pages/SubmitQuestion.jsx';
import NotFound from './pages/NotFound.jsx';

import AdminLayout from './pages/admin/AdminLayout.jsx';
import AdminDashboard from './pages/admin/AdminDashboard.jsx';
import AdminVendors from './pages/admin/AdminVendors.jsx';
import AdminCourses from './pages/admin/AdminCourses.jsx';
import AdminQuestions from './pages/admin/AdminQuestions.jsx';
import AdminImport from './pages/admin/AdminImport.jsx';
import AdminApprovals from './pages/admin/AdminApprovals.jsx';
import AdminUsers from './pages/admin/AdminUsers.jsx';
import AdminFinance from './pages/admin/AdminFinance.jsx';

export default function App() {
  return (
    <>
      <Navbar />
      <main>
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/login" element={<Login />} />
          <Route path="/register" element={<Register />} />
          <Route path="/forgot-password" element={<ForgotPassword />} />
          <Route path="/vendors" element={<Vendors />} />
          <Route path="/vendors/:slug" element={<VendorCourses />} />
          <Route path="/courses/:slug" element={<CourseDetail />} />

          <Route
            path="/exam/:slug"
            element={<ProtectedRoute><ExamRunner /></ProtectedRoute>}
          />
          <Route
            path="/result/:attemptId"
            element={<ProtectedRoute><Result /></ProtectedRoute>}
          />
          <Route
            path="/dashboard"
            element={<ProtectedRoute><Dashboard /></ProtectedRoute>}
          />
          <Route
            path="/account"
            element={<ProtectedRoute><Account /></ProtectedRoute>}
          />
          <Route
            path="/contribute"
            element={<ProtectedRoute><Contribute /></ProtectedRoute>}
          />
          <Route
            path="/courses/:slug/contribute"
            element={<ProtectedRoute><SubmitQuestion /></ProtectedRoute>}
          />

          <Route path="/admin" element={<AdminRoute><AdminLayout /></AdminRoute>}>
            <Route index element={<AdminDashboard />} />
            <Route path="vendors" element={<AdminVendors />} />
            <Route path="courses" element={<AdminCourses />} />
            <Route path="courses/:courseId/questions" element={<AdminQuestions />} />
            <Route path="import" element={<AdminImport />} />
            <Route path="approvals" element={<AdminApprovals />} />
            <Route path="users" element={<SuperAdminRoute><AdminUsers /></SuperAdminRoute>} />
            <Route path="finance" element={<SuperAdminRoute><AdminFinance /></SuperAdminRoute>} />
          </Route>

          <Route path="*" element={<NotFound />} />
        </Routes>
      </main>
      <Footer />
      <WhatsAppButton />
    </>
  );
}
