import { getAllModules, MODULE_CATEGORY_LABELS } from '@/core/module-registry';
import type { ModuleCategory } from '@/core/module-registry';

export interface NavGroup {
  category: ModuleCategory;
  label: string;
  items: NavItem[];
}

export interface NavItem {
  id: string;
  label: string;
  icon: string;
  href: string;
  featureFlag: string;
}

const CATEGORY_ORDER: ModuleCategory[] = [
  'operations',
  'generators',
  'management',
  'tools',
  'ai',
];

export function buildNavigation(): NavGroup[] {
  const modules = getAllModules();
  const groups: NavGroup[] = [];

  for (const category of CATEGORY_ORDER) {
    const items = modules
      .filter((m) => m.category === category)
      .map((m) => ({
        id: m.id,
        label: m.name,
        icon: m.icon,
        href: m.route,
        featureFlag: m.featureFlag,
      }));

    if (items.length > 0) {
      groups.push({
        category,
        label: MODULE_CATEGORY_LABELS[category],
        items,
      });
    }
  }

  return groups;
}
