import { Routes, Route, Navigate } from 'react-router-dom'
import { useAuth } from './contexts/AuthContext'
import Layout from './components/layout/Layout'
import LoginPage from './pages/LoginPage'
import DashboardPage from './pages/DashboardPage'
import WasteConfigurationPage from './pages/configuration/WasteConfigurationPage'
import RegulatorsConfigurationPage from './pages/configuration/RegulatorsConfigurationPage'
import ServicesConfigurationPage from './pages/configuration/ServicesConfigurationPage'
import WasteOriginsConfigurationPage from './pages/configuration/WasteOriginsConfigurationPage'
import TransportersConfigurationPage from './pages/configuration/TransportersConfigurationPage'
import ModuleComponentsConfigurationPage from './pages/configuration/ModuleComponentsConfigurationPage'
import EcosystemsConfigurationPage from './pages/configuration/EcosystemsConfigurationPage'
import RegulationCharacteristicsConfigurationPage from './pages/configuration/RegulationCharacteristicsConfigurationPage'
import ProjectListPage from './pages/projects/ProjectListPage'
import ProjectConfigurationPage from './pages/projects/ProjectConfigurationPage'
import TreatmentSitesPage from './pages/projects/TreatmentSitesPage'
import WasteSitesPage from './pages/projects/WasteSitesPage'
import InvestorsPage from './pages/projects/InvestorsPage'
import AdministrativeProceduresPage from './pages/projects/AdministrativeProceduresPage'
import YieldsPage from './pages/YieldsPage'
import BusinessPlanPage from './pages/BusinessPlanPage'
import SettingsPage from './pages/SettingsPage'
import HelpPage from './pages/HelpPage'

function App() {
  const { isAuthenticated } = useAuth()

  if (!isAuthenticated) {
    return (
      <Routes>
        <Route path="/login" element={<LoginPage />} />
        <Route path="*" element={<Navigate to="/login" replace />} />
      </Routes>
    )
  }

  return (
    <Layout>
      <Routes>
        <Route path="/" element={<DashboardPage />} />
        <Route path="/configuration/waste" element={<WasteConfigurationPage />} />
        <Route path="/configuration/regulators" element={<RegulatorsConfigurationPage />} />
        <Route path="/configuration/services" element={<ServicesConfigurationPage />} />
        <Route path="/configuration/waste-origins" element={<WasteOriginsConfigurationPage />} />
        <Route path="/configuration/transporters" element={<TransportersConfigurationPage />} />
        <Route path="/configuration/module-components" element={<ModuleComponentsConfigurationPage />} />
        <Route path="/configuration/ecosystems" element={<EcosystemsConfigurationPage />} />
        <Route path="/configuration/regulation-characteristics" element={<RegulationCharacteristicsConfigurationPage />} />
        <Route path="/projects" element={<ProjectListPage />} />
        <Route path="/projects/new" element={<ProjectConfigurationPage />} />
        <Route path="/projects/:id" element={<ProjectConfigurationPage />} />
        <Route path="/projects/treatment-sites" element={<TreatmentSitesPage />} />
        <Route path="/projects/waste-sites" element={<WasteSitesPage />} />
        <Route path="/projects/investors" element={<InvestorsPage />} />
        <Route path="/projects/procedures" element={<AdministrativeProceduresPage />} />
        <Route path="/yields" element={<YieldsPage />} />
        <Route path="/business-plan" element={<BusinessPlanPage />} />
        <Route path="/settings" element={<SettingsPage />} />
        <Route path="/help" element={<HelpPage />} />
        <Route path="*" element={<Navigate to="/" replace />} />
      </Routes>
    </Layout>
  )
}

export default App
