import { createRouter, createRootRoute, createRoute, Outlet } from '@tanstack/react-router';
import { AppShell } from '../components/layout/AppShell';
import { RafaelPainel } from '../cockpits/rafael/RafaelPainel';
import { ClientsPage } from '../cockpits/rafael/ClientsPage';
import { ClientDetailPage } from '../cockpits/rafael/ClientDetailPage';
import { OrdersPage } from '../cockpits/rafael/OrdersPage';
import { OrderDetailPage } from '../cockpits/rafael/OrderDetailPage';
import { NewOrderPage } from '../cockpits/rafael/NewOrderPage';
import { ApprovalQueuePage } from '../cockpits/sandra/ApprovalQueuePage';

const rootRoute = createRootRoute({
  component: () => (
    <AppShell>
      <Outlet />
    </AppShell>
  ),
});

const indexRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/',
  component: RafaelPainel,
});

const rafaelRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/rep',
  component: RafaelPainel,
});

const clientesRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/clientes',
  component: ClientsPage,
});

const clienteDetailRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/clientes/$id',
  component: ClientDetailPage,
});

const pedidosRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/pedidos',
  component: OrdersPage,
});

const novoOrderRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/pedidos/novo',
  component: NewOrderPage,
});

const pedidoDetailRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/pedidos/$id',
  component: OrderDetailPage,
});

const aprovacoes = createRoute({
  getParentRoute: () => rootRoute,
  path: '/aprovacoes',
  component: ApprovalQueuePage,
});

const routeTree = rootRoute.addChildren([
  indexRoute,
  rafaelRoute,
  clientesRoute,
  clienteDetailRoute,
  pedidosRoute,
  novoOrderRoute,
  pedidoDetailRoute,
  aprovacoes,
]);

export const router = createRouter({
  routeTree,
  defaultPreload: 'intent',
  defaultPreloadStaleTime: 0,
});

declare module '@tanstack/react-router' {
  interface Register {
    router: typeof router;
  }
}
