import { setupLayouts } from 'virtual:generated-layouts'
import generatedRoutes from 'virtual:generated-pages'
import pageRoute from './modules/page'
import type { Route } from '@/global'
import useSettingsStore from '@/store/modules/settings'
// 固定路由（默认路由）
const constantRoutes: Route.recordRaw[] = [
  {
    path: '/device',
    redirect: '/device/list',
    meta: {
      title: '',
    },
  },
  {
    path: '/:all(.*)*',
    name: 'notFound',
    component: () => import('@/views/[...all].vue'),
    meta: {
      title: '找不到页面',
    },
  },
]

// 系统路由
const systemRoutes: Route.recordRaw[] = [
  {
    path: '/dashboard',
    component: () => import('@/layouts/index.vue'),
    meta: {
      title: () => useSettingsStore().dashboard.title,
      breadcrumb: false,
    },
    children: [
      {
        path: '',
        name: 'dashboard',
        component: () => import('@/views/index.vue'),
        meta: {
          title: () => useSettingsStore().dashboard.title,
          breadcrumb: false,
        },
      },
    ],
  },
  {
    path: '/reload',
    component: () => import('@/layouts/index.vue'),
    meta: {
      title: '重新加载',
      breadcrumb: false,
    },
    children: [
      {
        path: '',
        name: 'reload',
        component: () => import('@/views/reload.vue'),
        meta: {
          title: '重新加载',
          breadcrumb: false,
        },
      },
    ],
  },
]

// 动态路由（异步路由、导航栏路由）
const asyncRoutes: Route.recordMainRaw[] = [
  {
    meta: {
      title: '设备管理',
      icon: '',
    },
    children: [
      ...pageRoute,
    ],
  },
]

const constantRoutesByFilesystem = generatedRoutes.filter((item) => {
  return item.meta?.enabled !== false && item.meta?.constant === true
})

const asyncRoutesByFilesystem = setupLayouts(generatedRoutes.filter((item) => {
  return item.meta?.enabled !== false && item.meta?.constant !== true && item.meta?.layout !== false
})) as Route.recordRaw[]

export {
  constantRoutes,
  systemRoutes,
  asyncRoutes,
  constantRoutesByFilesystem,
  asyncRoutesByFilesystem,
}
