import { Suspense } from "react";
import { Routes as ReactRoutes, Route, Navigate } from "react-router-dom";
import { HomePage } from "@/pages/home.page";
import { ThemesPage } from "@/pages/themes.page";
import { TestPage } from "@/pages/test.page";
import { Test2Page, type GraphData } from "@/pages/test2.page";
import { AuthPage } from "@/pages/auth.page";
import { RegisterPage } from "@/pages/register.page";
import { DefaultLayout } from "@/shared/layouts/DefaultLayout";
import { AddAgentsPage } from "@/pages/add-agents.page";
import { IDEPage } from "@/pages/ide.page";
import { TemplatesPage } from "@/pages/templates.page";

export const mockGraphData: GraphData = {
  nodes: [
    {
      id: "api-gateway",
      name: "API Gateway",
      type: "service",
      val: 12,
      description: "Входная точка API",
    },
    {
      id: "auth-service",
      name: "Auth Service",
      type: "service",
      val: 12,
      description: "Аутентификация",
    },
    {
      id: "db-service",
      name: "Database",
      type: "service",
      val: 12,
      description: "Хранилище данных",
    },
    {
      id: "redis-service",
      name: "Redis",
      type: "service",
      val: 12,
      description: "Кэширование",
    },
    {
      id: "queue-service",
      name: "Message Queue",
      type: "service",
      val: 12,
      description: "Очередь сообщений",
    },
    {
      id: "user-agent",
      name: "User Agent",
      type: "agent",
      val: 8,
      description: "Обработка пользователей",
    },
    {
      id: "payment-agent",
      name: "Payment Agent",
      type: "agent",
      val: 8,
      description: "Платежи",
    },
    {
      id: "notification-agent",
      name: "Notification Agent",
      type: "agent",
      val: 8,
      description: "Уведомления",
    },
    {
      id: "analytics-agent",
      name: "Analytics Agent",
      type: "agent",
      val: 8,
      description: "Аналитика",
    },
    {
      id: "report-agent",
      name: "Report Agent",
      type: "agent",
      val: 8,
      description: "Отчеты",
    },
  ],
  links: [
    { source: "user-agent", target: "api-gateway", type: "uses" },
    { source: "user-agent", target: "auth-service", type: "uses" },
    { source: "user-agent", target: "db-service", type: "uses" },
    { source: "payment-agent", target: "api-gateway", type: "uses" },
    { source: "payment-agent", target: "auth-service", type: "uses" },
    { source: "payment-agent", target: "queue-service", type: "uses" },
    { source: "notification-agent", target: "redis-service", type: "uses" },
    { source: "notification-agent", target: "queue-service", type: "uses" },
    { source: "analytics-agent", target: "db-service", type: "uses" },
    { source: "report-agent", target: "db-service", type: "uses" },
    { source: "report-agent", target: "redis-service", type: "uses" },
    { source: "api-gateway", target: "auth-service", type: "depends_on" },
    { source: "auth-service", target: "db-service", type: "depends_on" },
    { source: "api-gateway", target: "queue-service", type: "depends_on" },
    { source: "queue-service", target: "redis-service", type: "depends_on" },
  ],
};

export const Routing = () => {
  return (
    <Suspense
      fallback={
        <div className="flex items-center justify-center min-h-screen">
          Загрузка...
        </div>
      }
    >
      <ReactRoutes>
        <Route path="/auth" element={<AuthPage />} />
        <Route path="/register" element={<RegisterPage />} />

        <Route element={<DefaultLayout />}>
          <Route path="/" element={<HomePage />} />
          <Route path="/themes" element={<ThemesPage />} />
          <Route path="/add-agents" element={<AddAgentsPage />} />
          <Route path="/IDE" element={<IDEPage />} />
          <Route path="/templates" element={<TemplatesPage />} />
        </Route>

        <Route path="/test" element={<TestPage />} />

        <Route path="/test2" element={<Test2Page data={mockGraphData} />} />

        <Route path="*" element={<Navigate to="/" replace />} />
      </ReactRoutes>
    </Suspense>
  );
};
