import { Routes, Route } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { AuthProvider } from './contexts/auth/AuthContext';
import { AdminRoute } from './components/auth/AdminRoute';

// Public pages
import { HomePage } from '@/pages/home';
// import SpeciesDetail from './pages/species-detail'; // This will be created later

// Admin pages
import AdminLogin from '@/pages/admin/login';
import AdminDashboard from '@/pages/admin/dashboard';
import SpeciesList from '@/pages/admin/species/list';
import SpeciesEdit from '@/pages/admin/species/edit';
import SpeciesCreate from '@/pages/admin/species/create';
import CitesListingsList from '@/pages/admin/cites-listings/list';
import CitesListingsEdit from '@/pages/admin/cites-listings/edit';
import CitesListingsCreate from '@/pages/admin/cites-listings/create';
import IucnAssessmentsList from '@/pages/admin/iucn-assessments/list';
import IucnAssessmentsEdit from '@/pages/admin/iucn-assessments/edit';
import IucnAssessmentsCreate from '@/pages/admin/iucn-assessments/create';
import CommonNamesList from '@/pages/admin/common-names/list';
import CommonNamesEdit from '@/pages/admin/common-names/edit';
import CommonNamesCreate from '@/pages/admin/common-names/create';
// ...other admin page imports

const queryClient = new QueryClient();

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <AuthProvider>
        <div className="min-h-screen bg-background">
          <Routes>
            {/* Public routes */}
            <Route path="/" element={<HomePage />} />
            {/* <Route path="/species/:id" element={<SpeciesDetail />} /> */}
            
            {/* Admin authentication */}
            <Route path="/admin/login" element={<AdminLogin />} />
            
            {/* Protected admin routes */}
            <Route element={<AdminRoute />}>
              <Route path="/admin" element={<AdminDashboard />} />
              
              {/* Species management */}
              <Route path="/admin/species" element={<SpeciesList />} />
              <Route path="/admin/species/create" element={<SpeciesCreate />} />
              <Route path="/admin/species/:id/edit" element={<SpeciesEdit />} />
              
              {/* CITES listings management */}
              <Route path="/admin/cites-listings" element={<CitesListingsList />} />
              <Route path="/admin/cites-listings/create" element={<CitesListingsCreate />} />
              <Route path="/admin/cites-listings/:id/edit" element={<CitesListingsEdit />} />
              
              {/* IUCN Assessments management */}
              <Route path="/admin/iucn-assessments" element={<IucnAssessmentsList />} />
              <Route path="/admin/iucn-assessments/create" element={<IucnAssessmentsCreate />} />
              <Route path="/admin/iucn-assessments/:id/edit" element={<IucnAssessmentsEdit />} />
              
              {/* Common Names management */}
              <Route path="/admin/common-names" element={<CommonNamesList />} />
              <Route path="/admin/common-names/create" element={<CommonNamesCreate />} />
              <Route path="/admin/common-names/:id/edit" element={<CommonNamesEdit />} />
              
              {/* Other admin routes... */}
            </Route>

            <Route path="*" element={<div className="container p-8 text-center">Page not found</div>} />
          </Routes>
        </div>
      </AuthProvider>
    </QueryClientProvider>
  );
}

export default App;