import { createRouter, createWebHashHistory } from 'vue-router';
import { IParam } from '@core';

const routes = [
  {
    path: "/apps/:app?",
    beforeEnter: async (to: any, from: any) => {
      const appParams:IParam = {};
      const auth: Promise<any> = await App.initAppAuth(appParams);
      return auth;
    },
    meta: {  
      tag: '{{app.defaultPSAppIndexView.codeName}}'
    },
    component: () => import("@views/{{spinalCase app.defaultPSAppIndexView.psAppModule.codeName}}/{{spinalCase app.defaultPSAppIndexView.codeName}}"),
    children: [
      {{#each app.appEntityResources as |appEntityResource|}}
        {{#if appEntityResource.appDataEntity.allPSAppViews}}
            {{#each appEntityResource.appDataEntity.allPSAppViews as |appView|}}
            {{#if (eq appView.getRefFlag true)}}
            {{#if (or (eq appView.viewType 'DEEDITVIEW') (eq appView.viewType 'DEGRIDVIEW') (eq appView.viewType 'DETREEEXPVIEW'))}}
            {
              path: "{{appEntityResource.path}}/views/{{lowerCase appView.codeName}}",
              meta: {
                  tag:'{{appView.codeName}}'
              },
              component: () => import("@views/{{spinalCase appView.psAppModule.codeName}}/{{spinalCase appView.codeName}}"),
            },
            {{/if}}
            {{/if}}
            {{/each}}
        {{/if}}
      {{/each}}
    ]
  },
  {
    path: "/",
    redirect: "/apps/{{lowerCase app.codeName}}"
  },
  {
    path: '/login',
    name: 'login',
    component: () => import("@components/common/login.vue")
  }
]
const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

/**
 * 全局路由守卫
 */
router.beforeEach((to, from, next) => {
  next();
})
export default router;