import { createRouter, createWebHistory } from 'vue-router'
import LoginView from './views/LoginView.vue'

// Route-level splitting keeps Mission Control's first visible result small;
// data views and their editors are loaded only when the operator opens them.
const NexusLayout = () => import('./layouts/NexusLayout.vue')
const FlowBoard = () => import('./views/Dashboard/FlowBoard.vue')
const ProjectsIndexView = () => import('./views/ProjectsIndexView.vue')
const ProjectDetailView = () => import('./views/ProjectDetailView.vue')
const SettingsView = () => import('./views/SettingsView.vue')
const MemoryView = () => import('./views/MemoryView.vue')
const DocsView = () => import('./views/DocsView.vue')
const AgentDetailView = () => import('./views/AgentDetailView.vue')
const AgentsIndexView = () => import('./views/AgentsIndexView.vue')
const AgentCreateView = () => import('./views/AgentCreateView.vue')
const AgentProposalDetailView = () => import('./views/AgentProposalDetailView.vue')
const SecurityView = () => import('./views/SecurityView.vue')
const IncidentsView = () => import('./views/IncidentsView.vue')
const CalendarView = () => import('./views/CalendarView.vue')
const TaskBoardView = () => import('./views/TaskBoardView.vue')
const TaskDetailView = () => import('./views/TaskDetailView.vue')
const NotificationsView = () => import('./views/NotificationsView.vue')
const RunControlView = () => import('./views/RunControlView.vue')
const ModelsView = () => import('./views/ModelsView.vue')
const ActivityView = () => import('./views/ActivityView.vue')
const RunDetailView = () => import('./views/RunDetailView.vue')

const routes = [
  { path: '/login', name: 'Login', component: LoginView, meta: { public: true } },
  { path: '/', redirect: '/dashboard' },

  // V2 Dashboard (neues NexusLayout + FlowBoard)
  {
    path: '/dashboard',
    component: NexusLayout,
    children: [
      { path: '', name: 'Dashboard', component: FlowBoard },
    ],
  },

  { path: '/memory', name: 'Memory', component: MemoryView, meta: { standalone: true } },
  { path: '/docs', name: 'Docs', component: DocsView, meta: { standalone: true } },
  { path: '/agents/new', name: 'AgentCreate', component: AgentCreateView, meta: { standalone: true } },
  {
    path: '/agents/proposals/:proposalId',
    name: 'AgentProposalDetail',
    component: AgentProposalDetailView,
    meta: { standalone: true },
  },
  { path: '/agents/:id', name: 'AgentDetail', component: AgentDetailView, meta: { standalone: true } },
  { path: '/security', name: 'Security', component: SecurityView, meta: { standalone: true } },
  { path: '/incidents', name: 'Incidents', component: IncidentsView, meta: { standalone: true } },
  { path: '/calendar', name: 'Calendar', component: CalendarView, meta: { standalone: true } },
  { path: '/projects', name: 'Projects', component: ProjectsIndexView, meta: { standalone: true } },
  { path: '/projects/:id', name: 'ProjectDetail', component: ProjectDetailView, meta: { standalone: true } },
  { path: '/tasks', name: 'Task Board', component: TaskBoardView, meta: { standalone: true } },
  { path: '/tasks/:id', name: 'TaskDetail', component: TaskDetailView, meta: { standalone: true } },
  { path: '/agents', name: 'Agents', component: AgentsIndexView, meta: { standalone: true } },
  { path: '/runs', name: 'Run Control', component: RunControlView, meta: { standalone: true } },
  { path: '/runs/:id', name: 'RunDetail', component: RunDetailView, meta: { standalone: true } },
  { path: '/models', name: 'Models', component: ModelsView, meta: { standalone: true } },
  { path: '/activity', name: 'Activity', component: ActivityView, meta: { standalone: true } },
  { path: '/notifications', name: 'Notifications', component: NotificationsView, meta: { standalone: true } },
  { path: '/settings', name: 'Settings', component: SettingsView, meta: { standalone: true } },
  { path: '/:pathMatch(.*)*', redirect: '/dashboard' },
]

export default createRouter({
  history: createWebHistory(),
  routes,
})
