import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'chat',
    component: () => import('@/views/ChatView.vue'),
    meta: { title: '智能对话' },
  },
  {
    path: '/workflow',
    name: 'workflow',
    component: () => import('@/views/WorkflowView.vue'),
    meta: { title: '工作流' },
  },
  {
    path: '/knowledge',
    name: 'knowledge',
    component: () => import('@/views/KnowledgeBaseView.vue'),
    meta: { title: '知识库' },
  },
  {
    path: '/skills',
    name: 'skills',
    component: () => import('@/views/SkillsView.vue'),
    meta: { title: '技能' },
  },
  {
    path: '/terminal',
    name: 'terminal',
    component: () => import('@/views/TerminalView.vue'),
    meta: { title: '终端' },
  },
  {
    path: '/computer-use',
    name: 'computer-use',
    component: () => import('@/views/ComputerUseView.vue'),
    meta: { title: 'Computer Use' },
  },
  {
    path: '/evolution',
    name: 'evolution',
    component: () => import('@/views/EvolutionView.vue'),
    meta: { title: '自进化' },
  },
  {
    path: '/settings',
    name: 'settings',
    component: () => import('@/views/SettingsView.vue'),
    meta: { title: '设置' },
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach((to, _from, next) => {
  const title = to.meta.title as string | undefined
  if (title) {
    document.title = `${title} - Fischer AgentKit`
  }
  next()
})

export default router
