import { setupLayouts } from 'virtual:generated-layouts'
import generatedRoutes from 'virtual:generated-pages'
// import MultilevelMenuExample from './modules/multilevel.menu.example'
// import BreadcrumbExample from './modules/breadcrumb.example'
import systemRoute from './modules/system'
import dataRoute from './modules/data'
import footprintRoute from './modules/carbonFootprint'
import evaluateRoute from './modules/carbonEvaluate'
import warningRoute from './modules/carbonWarning'
import dashboard from './modules/dashboard'
import electricityRouter from './modules/useElectricity'
import hotRouter from './modules/useHot'
import gasRouter from './modules/useGas'
import environment from './modules/environment'
// import electricityRoute from './modules/electricity'
import countRoute from './modules/carbonCount'
import type { Route } from '@/global'
import useSettingsStore from '@/store/modules/settings'
// 固定路由（默认路由）
const constantRoutes: Route.recordRaw[] = [
  {
    path: '/',
    redirect: '/dashboard',
    meta: {
      title: '首页',
    },
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login.vue'),
    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: '/personal',
    component: () => import('@/layouts/index.vue'),
    redirect: '/personal/setting',
    meta: {
      title: '个人中心',
      breadcrumb: false,
    },
    children: [
      {
        path: 'setting',
        name: 'personalSetting',
        component: () => import('@/views/personal/setting.vue'),
        meta: {
          title: '个人设置',
          cache: 'personalEditPassword',
        },
      },
      {
        path: 'edit/password',
        name: 'personalEditPassword',
        component: () => import('@/views/personal/edit.password.vue'),
        meta: {
          title: '修改密码',
        },
      },
    ],
  },
  {
    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: '',
  //     auth: 'zlgl',
  //   },
  //   children: [
  //     MultilevelMenuExample,
  //     BreadcrumbExample,
  //   ],
  // },
  {
    meta: {
      title: '首页',
      icon: '',
      auth: '/dashboard',
    },
    children: [
      ...dashboard,
    ],
  },
  {
    meta: {
      title: '用电监测',
      icon: '',
      auth: '/electricity',
    },
    children: [
      ...electricityRouter,
    ],
  },
  {
    meta: {
      title: '用热监测',
      icon: '',
      auth: '/hot',
    },
    children: [
      ...hotRouter,
    ],
  },
  {
    meta: {
      title: '用气监测',
      icon: '',
      auth: '/consumption',
    },
    children: [
      ...gasRouter,
    ],
  },
  {
    meta: {
      title: '环境监测',
      icon: '',
      auth: '/environment',
    },
    children: [
      ...environment,
    ],
  },
  {
    meta: {
      title: '数据管理',
      icon: '',
      auth: '/dataset',
    },
    children: [
      ...dataRoute,
    ],
  },
  {
    meta: {
      title: '电力碳核算',
      icon: '',
      auth: '/count',
    },
    children: [
      ...countRoute,
    ],
  },
  {
    meta: {
      title: '碳足迹监测',
      icon: '',
      auth: '/footprint',
    },
    children: [
      ...footprintRoute,
    ],
  },
  {
    meta: {
      title: '碳足迹评价',
      icon: '',
      auth: '/evaluate',
    },
    children: [
      ...evaluateRoute,
    ],
  },
  {
    meta: {
      title: '碳足迹预警',
      icon: '',
      auth: '/warning',
    },
    children: [
      ...warningRoute,
    ],
  },
  // {
  //   meta: {
  //     title: '碳足迹决策',
  //     icon: '',
  //     auth: '/decision',
  //   },
  //   children: [
  //     ...decisionRoute,
  //   ],
  // },
  // {
  //   meta: {
  //     title: '电网管理',
  //     icon: '',
  //     auth: '/electricity',
  //   },
  //   children: [
  //     ...electricityRoute,
  //   ],
  // },
  {
    meta: {
      title: '系统设置',
      icon: '',
      auth: '/system',
    },
    children: [
      ...systemRoute,
    ],
  },
]

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,
}
