import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const ctx = import.meta.glob('../views/**/App*.vue', {eager: true})
const routes = [{path: '/', name: 'home'}]
Object.values(ctx).map(file => {
  if (file.default) {
    let {name, label = name, path = `/apps/${name}`} = file.default
    routes.push({name, path, label, component: file.default})
  }
})
localStorage.setItem('routes', JSON.stringify(routes.slice(1).map(v => ({name: v.name, label: v.label, path: v.path}))))

export default new VueRouter({
  mode: 'history', routes
})
