import { createRouter, createWebHistory } from 'vue-router'
import { useDynamicRoutes } from '@/router/route.ts'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: () => import('../layout/LayoutPage.vue'),
      children: [
        {
          path: '',
          name: 'home',
          component: () => import('@/views/HomeView.vue'),
        }
      ],
    },
    {
      path:"/NotFound404",
      name:"404",
      component: () => import('../views/NotFound404View.vue'),
    },
    {
      path: '/:pathMatch(.*)*',
      redirect: '/NotFound404'
    },
  ],
})
console.log(router.getRoutes())
const dynamicRoutesList = useDynamicRoutes()
dynamicRoutesList.forEach(item => {
  router.addRoute('layout', {
    path: item.path,
    name: item.name,
    component: () => import(`/src/${item.addr}`)
  })
})
console.log(router.getRoutes())

export default router
