/**
 * Routes Configuration
 * Defines menu hierarchy, breadcrumbs, and routing structure
 */

export interface RouteConfig {
  path: string;
  label: string;
  icon?: string;
  children?: RouteConfig[];
  breadcrumb?: string;
}

export const routes: RouteConfig[] = [
  {
    path: '/',
    label: 'Dashboard',
    icon: 'Dashboard',
  },
  {
    path: '/planner',
    label: 'Planner',
    icon: 'Planner',
    children: [
      { path: '/planner', label: 'Dashboard', breadcrumb: 'Planner Dashboard' },
      { path: '/planner/keywords', label: 'Keywords', breadcrumb: 'Keywords' },
      { path: '/planner/clusters', label: 'Clusters', breadcrumb: 'Clusters' },
      { path: '/planner/ideas', label: 'Ideas', breadcrumb: 'Ideas' },
      { path: '/planner/mapping', label: 'Mapping', breadcrumb: 'Mapping' },
    ],
  },
  {
    path: '/writer',
    label: 'Writer',
    icon: 'Writer',
    children: [
      { path: '/writer', label: 'Dashboard', breadcrumb: 'Writer Dashboard' },
      { path: '/writer/tasks', label: 'Tasks', breadcrumb: 'Tasks' },
      { path: '/writer/content', label: 'Content', breadcrumb: 'Content' },
      { path: '/writer/published', label: 'Published', breadcrumb: 'Published' },
    ],
  },
  {
    path: '/thinker',
    label: 'Thinker',
    icon: 'Thinker',
    children: [
      { path: '/thinker', label: 'Dashboard', breadcrumb: 'Thinker Dashboard' },
      { path: '/thinker/prompts', label: 'Prompts', breadcrumb: 'Prompts' },
      { path: '/thinker/strategies', label: 'Strategies', breadcrumb: 'Strategies' },
      { path: '/thinker/profile', label: 'Profile', breadcrumb: 'Profile' },
    ],
  },
  {
    path: '/schedules',
    label: 'Schedules',
    icon: 'Schedules',
  },
];

export const getBreadcrumbs = (pathname: string): Array<{ label: string; path: string }> => {
  const breadcrumbs: Array<{ label: string; path: string }> = [
    { label: 'Home', path: '/' },
  ];

  // Find matching route
  const findRoute = (routes: RouteConfig[], path: string): RouteConfig | null => {
    for (const route of routes) {
      if (route.path === path) {
        return route;
      }
      if (route.children) {
        const child = route.children.find((r) => r.path === path);
        if (child) {
          return { ...child, path: route.path };
        }
        const found = findRoute(route.children, path);
        if (found) {
          breadcrumbs.push({ label: route.label, path: route.path });
          return found;
        }
      }
    }
    return null;
  };

  const route = findRoute(routes, pathname);
  if (route) {
    breadcrumbs.push({ label: route.breadcrumb || route.label, path: route.path });
  }

  return breadcrumbs;
};

