import React, { lazy, Suspense } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import { LoadingOverlay } from '@/components/shared/LoadingOverlay';
import { CnabLayout } from './layout/CnabLayout';

// Lazy load views
const DashboardView = lazy(() => import('./views/DashboardView'));
const FavorecidosView = lazy(() => import('./views/FavorecidosView'));
const GerarRemessaView = lazy(() => import('./views/GerarRemessaView'));
const GerenciarPastasView = lazy(() => import('./views/GerenciarPastasView'));
const TransacoesView = lazy(() => import('./views/TransacoesView'));

const PageLoader = () => (
  <LoadingOverlay isLoading={true} message="Carregando módulo..." fullScreen variant="premium" />
);

export const CnabRoutes = () => {
  return (
    <Suspense fallback={<PageLoader />}>
      <Routes>
        <Route element={<CnabLayout />}>
          <Route path="dashboard" element={<DashboardView />} />
          <Route path="transacoes" element={<TransacoesView />} />
          <Route path="favorecidos" element={<FavorecidosView />} />
          <Route path="gerar-remessa" element={<GerarRemessaView />} />
          <Route path="gerenciar-pastas" element={<GerenciarPastasView />} />
          <Route index element={<Navigate to="dashboard" replace />} />
        </Route>
      </Routes>
    </Suspense>
  );
};

export default CnabRoutes;
