import { Routes, Route, Navigate } from 'react-router-dom';
import {
  getPublicRoutes,
  getPublicStandaloneRoutes,
  getProtectedRoutes,
  getErrorRoutes,
} from './routeConfig';

export function AppRouter() {
  const publicRoutes = getPublicRoutes();
  const publicStandalone = getPublicStandaloneRoutes();
  const protectedRoutes = getProtectedRoutes();
  const errorRoutes = getErrorRoutes();

  return (
    <Routes>
      {publicRoutes.map(({ path, element }) => (
        <Route key={path} path={path} element={element} />
      ))}
      {publicStandalone.map(({ path, element }) => (
        <Route key={path} path={path} element={element} />
      ))}
      {protectedRoutes.map(({ path, element }) => (
        <Route key={path} path={path} element={element} />
      ))}
      {errorRoutes.map(({ path, element }) => (
        <Route key={path} path={path} element={element} />
      ))}
      <Route path="/" element={<Navigate to="/dashboard" replace />} />
      <Route path="*" element={<Navigate to="/404" replace />} />
    </Routes>
  );
}
