import { Routes, Route, Navigate } from 'react-router-dom'
import Landing from './pages/Landing'
import Login from './pages/Login'
import Layout from './components/Layout'
import Dashboard from './pages/Dashboard'
import Demandas from './pages/Demandas'
import Orcamentos from './pages/Orcamentos'
import OrdensServico from './pages/OrdensServico'
import Fornecedores from './pages/Fornecedores'
import Relatorios from './pages/Relatorios'
import ESG from './pages/ESG'
import KPIs from './pages/KPIs'
import Auditoria from './pages/Auditoria'
import Importacao from './pages/Importacao'
import Metas from './pages/Metas'
import AlertasConfig from './pages/AlertasConfig'
import Usuarios from './pages/Usuarios'
import Configuracao from './pages/Configuracao'

interface PrivateRouteProps {
  children: React.ReactNode;
}

function PrivateRoute({ children }: PrivateRouteProps) {
  const token = localStorage.getItem('token')
  return token ? <>{children}</> : <Navigate to="/login" />
}

export default function App() {
  return (
    <Routes>
      <Route path="/" element={<Landing />} />
      <Route path="/login" element={<Login />} />
      <Route path="/app" element={<PrivateRoute><Layout /></PrivateRoute>}>
        <Route index element={<Dashboard />} />
        <Route path="demandas" element={<Demandas />} />
        <Route path="orcamentos" element={<Orcamentos />} />
        <Route path="ordens-servico" element={<OrdensServico />} />
        <Route path="fornecedores" element={<Fornecedores />} />
        <Route path="relatorios" element={<Relatorios />} />
        <Route path="esg" element={<ESG />} />
        <Route path="kpis" element={<KPIs />} />
        <Route path="auditoria" element={<Auditoria />} />
        <Route path="importacao" element={<Importacao />} />
        <Route path="metas" element={<Metas />} />
        <Route path="alertas-config" element={<AlertasConfig />} />
        <Route path="configuracao" element={<Configuracao />} />
        <Route path="usuarios" element={<Usuarios />} />
      </Route>
      <Route path="*" element={<Navigate to="/" />} />
    </Routes>
  )
}
