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

const routes = [
  {
    path: '/',
    redirect: '/system-config'
  },
  {
    path: '/real-time-status',
    name: 'RealTimeStatus',
    component: () => import('../views/RealTimeStatus.vue'),
    meta: { title: '实时状态' }
  },
  {
    path: '/system-config',
    name: 'SystemConfig',
    component: SystemConfig,
    meta: { title: '系统配置' }
  },
  {
    path: '/network-config',
    name: 'NetworkConfig',
    component: () => import('../views/NetworkConfig.vue'),
    meta: { title: '网络配置' }
  },
  {
    path: '/led-debug',
    name: 'LedDebug',
    component: () => import('../views/LedDebug.vue'),
    meta: { title: 'LED调试' }
  },
  {
    path: '/port-status',
    name: 'PortStatus',
    component: () => import('../views/PortStatus.vue'),
    meta: { title: '端口状态' }
  },
  {
    path: '/panel-status',
    name: 'PanelStatus',
    component: () => import('../views/PanelStatus.vue'),
    meta: { title: '面板状态' }
  },
  {
    path: '/alarm-status',
    name: 'AlarmStatus',
    component: () => import('../views/AlarmStatus.vue'),
    meta: { title: '告警显示' }
  },
  {
    path: '/ota-upgrade',
    name: 'OTAUpgrade',
    component: () => import('../views/OTAUpgrade.vue'),
    meta: { title: 'OTA升级' }
  },
  {
    path: '/env-sensor',
    name: 'EnvSensor',
    component: () => import('../views/EnvSensor.vue'),
    meta: { title: '环境传感器' }
  },
  {
    path: '/jumper-status',
    name: 'JumperStatus',
    component: () => import('../views/JumperStatus.vue'),
    meta: { title: '跳线器状态' }
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue'),
    meta: { title: '关于' }
  }
]

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

// 路由守卫，设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = `${to.meta.title} - 配线架配置`
  }
  next()
})

export default router