import { createRouter, createWebHistory, RouteRecordRaw, createWebHashHistory, Router } from 'vue-router';
import { useStore } from 'vuex';
import appSetting from '@/app-setting';
import HomeView from '../views/index.vue';

const constantRouterMap: RouteRecordRaw[] = [
    { path: '/login', component: () => import('@/views/auth/boxed-signin.vue'),meta: { layout: 'auth' } },
];
const router = createRouter({
    history: createWebHashHistory(),
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
})
const asyncRouterMap: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/dashboard',
        name: 'dashboard',
        children: [
            { path: 'dashboard', component: () => import('@/views/index.vue'), name: 'dashboard', meta: { title: 'home', icon: 'dashboard', layout: 'app'  } }
        ]
    },
    {
        path: '/stock',
        redirect: '/stock',
        name: 'stock',
        children: [
            { path: 'warehouseList', component: () => import('@/views/stock/warehouseList.vue'), name: 'warehouseList', meta: { title: 'warehouseList',layout: 'app' } },
            { path: 'goodsLend', component: () => import('@/views/stock/goodsLend.vue'), name: 'goodsLend', meta: { title: 'goodsLend',layout: 'app' } },
            { path: 'goodsTransfer', component: () => import('@/views/stock/goodsTransfer.vue'), name: 'goodsTransfer', meta: { title: 'goodsTransfer',layout: 'app' } },
        ]
    },
]
asyncRouterMap.forEach(route => {
    router.addRoute(route);
});
/* router.beforeEach((to, from, next) => {
    const store = useStore();
    //判断当前页面是否带有侧边栏及顶部
    if (to?.meta?.layout == 'auth') {
        store.dispatch("setMainLayout",'auth');
    } else {
        store.dispatch("setMainLayout",'app');
    }
    next(true);
}); */

export { constantRouterMap, asyncRouterMap };
export default router;
