import type { RouteRecordRaw } from 'vue-router'

const modules: Record<string, { default: RouteRecordRaw }> = import.meta.glob('./routes/*.ts', { eager: true })

export const constantRoutes: RouteRecordRaw[] = []
export const asyncRoutes: RouteRecordRaw[] = []
Object.keys(modules).forEach((path) => {
  const filename = getLastItem(path.split('/'))
  if (filename?.startsWith('_'))
    constantRoutes.push(modules[path].default)
  else
    asyncRoutes.push(modules[path].default)
})

// 传一个数组，获取数组最后一项
function getLastItem<T>(array: T[]): T {
  return array[array.length - 1]
}
