import { lazy, type ReactNode } from "react";
import { Soon } from "./components/Soon";

// 路由注册表 —— 控制台的单一事实源：导航 + 内容都从这里派生。
// 新增页面 = 在此加一条；real 页面用 lazy 懒加载（代码分割）。
const ModelsPage = lazy(() => import("./pages/ModelsPage").then((m) => ({ default: m.ModelsPage })));
const DatasourcesPage = lazy(() => import("./pages/DatasourcesPage").then((m) => ({ default: m.DatasourcesPage })));
const PricingPage = lazy(() => import("./pages/PricingPage").then((m) => ({ default: m.PricingPage })));

export interface RouteDef {
  path: string;
  label: string;
  group: string;
  ready?: boolean;
  element: ReactNode;
}

export const routes: RouteDef[] = [
  {
    path: "/models",
    label: "模型",
    group: "配置",
    ready: true,
    element: <ModelsPage />,
  },
  {
    path: "/datasources",
    label: "数据源",
    group: "配置",
    ready: true,
    element: <DatasourcesPage />,
  },
  {
    path: "/pricing",
    label: "计价",
    group: "配置",
    ready: true,
    element: <PricingPage />,
  },
  {
    path: "/tenants",
    label: "租户",
    group: "平台",
    element: <Soon title="租户 / 工作区" desc="多租户隔离、配额、用户与计费。垂直行业平台级复制的基座。" />,
  },
  {
    path: "/guardrails",
    label: "护栏",
    group: "平台",
    element: <Soon title="护栏" desc="输入/输出 Guardrail 规则（脱敏 / 免责 / 强制引用）。受监管垂直必备。" />,
  },
];

export const defaultPath = "/models";

// 派生分组导航（保持注册顺序）。
export function navGroups(): Array<{ group: string; items: RouteDef[] }> {
  const out: Array<{ group: string; items: RouteDef[] }> = [];
  for (const r of routes) {
    let g = out.find((x) => x.group === r.group);
    if (!g) {
      g = { group: r.group, items: [] };
      out.push(g);
    }
    g.items.push(r);
  }
  return out;
}
