import './App.css';
import Navbar from './components/Navbar';
import { BrowserRouter, Routes, Route, useLocation } from 'react-router-dom';
import React from 'react';
import CitizenHomePage from './pages/CitizenHomePage';
import Chatbot from './pages/Chatbot';
import PollsSurveys from './pages/PollsSurveys';
import Complaints from './pages/Complaints';
import Login from './pages/Login';
import Register from './pages/Register';
import ForgotPassword from './pages/ForgotPassword';
import AdminDashboard from './pages/admin/Dashboard';
import AdminComplaints from './pages/admin/Complaints';
import AdminPollsSurveys from './pages/admin/PollsSurveys';
import UsersAll from './pages/admin/UsersAll';
import Tenants from './pages/admin/Tenants';
import RolesPermissions from './pages/admin/RolesPermissions';
import Permissions from './pages/admin/Permissions';
import UserActivity from './pages/admin/UserActivity';
import SystemReports from './pages/admin/reports/SystemReports';
import EngagementReport from './pages/admin/reports/EngagementReport';
import UsageReport from './pages/admin/reports/UsageReport';
import PerformanceReport from './pages/admin/reports/PerformanceReport';
import Notifications from './pages/admin/Notifications';
import SystemSettings from './pages/admin/SystemSettings';

function AppRoutes() {
  const location = useLocation();
  const isChatbot = location.pathname === '/chatbot';
  const isAdmin = location.pathname.startsWith('/admin');
  const [showNavbar, setShowNavbar] = React.useState(!isChatbot && !isAdmin);

  React.useEffect(() => {
    setShowNavbar(!isChatbot && !isAdmin);
  }, [isChatbot, isAdmin]);

  return (
    <>
      {showNavbar && <Navbar />}
      <Routes>
        <Route path="/" element={<CitizenHomePage />} />
        <Route path="/chatbot" element={<Chatbot showNavbar={showNavbar} setShowNavbar={setShowNavbar} />} />
        <Route path="/polls-surveys" element={<PollsSurveys />} />
        <Route path="/complaints" element={<Complaints />} />
        <Route path="/login" element={<Login />} />
        <Route path="/register" element={<Register />} />
        <Route path="/forgot-password" element={<ForgotPassword />} />
  {/* Admin routes - no permissions required for now */}
  <Route path="/admin/dashboard" element={<AdminDashboard />} />
  <Route path="/admin/complaints" element={<AdminComplaints />} />
  <Route path="/admin/polls-surveys/*" element={<AdminPollsSurveys />} />
  <Route path="/admin/users/all" element={<UsersAll />} />
  <Route path="/admin/tenants" element={<Tenants />} />
  <Route path="/admin/users/roles" element={<RolesPermissions />} />
  <Route path="/admin/permissions/:roleId" element={<Permissions />} />
  <Route path="/admin/users/activity" element={<UserActivity />} />

  {/* System Reports */}
  <Route path="/admin/reports" element={<SystemReports />} />
  <Route path="/admin/reports/engagement" element={<EngagementReport />} />
  <Route path="/admin/reports/usage" element={<UsageReport />} />
  <Route path="/admin/reports/performance" element={<PerformanceReport />} />
  <Route path="/admin/notifications" element={<Notifications />} />
  <Route path="/admin/settings" element={<SystemSettings />} />
      </Routes>
    </>
  );
}

export default function App() {
  return (
    <BrowserRouter basename="/client">
      <AppRoutes />
    </BrowserRouter>
  );
}