import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router';
import { useAppStore } from '@/stores/index';
import appSetting from '@/app-setting';

import HomeView from '../views/apps/applist.vue'//'../views/index.vue';
/*import HomeView from '../views/auth/boxed-signin.vue';*/

const routes: RouteRecordRaw[] = [
    // dashboard
    {
        path: '/', name: 'home', component: HomeView, meta: {
            requiresAuth: true
        },
    },
    {
        path: '/dashboard',
        name: 'dashboard',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/apps/scrumboard.vue'),
    },
    {
        path: '/apps/scrumboard',
        name: 'scrumboard',
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/apps/scrumboard.vue'),
    },
    {
        path: '/login',
        name: 'login',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/auth/boxed-signin.vue'),
    },
    //订单页面
    {
        path: '/apps/order',
        name: 'order',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/apps/order.vue'),
    },
    //调拨单
    {
        path: '/allocation/index',
        name: 'allocation',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/allocation/index.vue'),
    },
    {
        path: '/allocation/check/:id',
        name: 'check',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/allocation/check.vue'),
    },
    //出入库
    {
        path: '/InoutStorage/index',
        name: 'InoutStorage',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/InoutStorage/index.vue'),
    },
    //入库
    {
        path: '/InoutStorage/inStorage/:id',
        name: 'inStorage',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/InoutStorage/inStorage.vue'),
    },
    //出库
    {
        path: '/InoutStorage/outStorage/:id',
        name: 'outStorage',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/InoutStorage/outStorage.vue'),
    },
    //盘点
    {
        path: '/Inventory/index',
        name: 'Inventory',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/Inventory/index.vue'),
    },
    {
        path: '/Inventory/addInventory/:id',
        name: 'addInventory',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/Inventory/addInventory.vue'),
    },
    //发货页面
    {
        path: '/apps/shippingPage/:id/:send_type',
        name: 'shippingPage',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/apps/shippingPage.vue'),
    },
    /* 列表页面 
    start
        库存列表 
    */
    {
        path: '/list/InventoryList',
        name: 'InventoryList',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/list/InventoryList.vue'),
    },
    //库位管理
    {
        path: '/list/locationList',
        name: 'locationList',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/list/locationList.vue'),
    },
    //库位报损
    {
        path: '/list/InventoryLoss',
        name: 'InventoryLoss',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/list/InventoryLoss.vue'),
    },
     //仓库列表
     {
        path: '/list/warehouseList',
        name: 'warehouseList',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/list/warehouseList.vue'),
    },
    //库位区域
    {
        path: '/list/locationArea',
        name: 'locationArea',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/list/locationArea.vue'),
    },
    //订单列表
    {
        path: '/list/orderList',
        name: 'orderList',
        meta: {
            requiresAuth: false,
            hideButtonGroup: true
        },
        component: () => import(/* webpackChunkName: "apps-scrumboard" */ '../views/list/orderList.vue'),
    },
    /* end */

    // apps
    {
        path: '/apps/applist',
        name: 'applist',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/apps/applist.vue'),
    },
    {
        path: '/apps/custom',
        name: 'custom',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/apps/custom.vue'),
    },
    {
        path: '/apps/stock',
        name: 'stock',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/apps/stock.vue'),
    },

    {
        path: '/apps/goods',
        name: 'goods',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-chat" */ '../views/apps/goods.vue'),
    },


    //user
    {
        path: '/users/contacts',
        name: 'contacts',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "apps-contacts" */ '../views/users/contacts.vue'),
    },


    {
        path: '/users/profile',
        name: 'profile',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "users-profile" */ '../views/users/profile.vue'),
    },

    {
        path: '/users/user-account-settings',
        name: 'user-account-settings',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "users-profile" */ '../views/users/user-account-settings.vue'),
    },
    // components
    {
        path: '/components/tabs',
        name: 'tabs',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-tabs" */ '../views/components/tabs.vue'),
    },
    {
        path: '/components/accordions',
        name: 'accordions',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-accordions" */ '../views/components/accordions.vue'),
    },
    {
        path: '/components/modals',
        name: 'modals',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-modals" */ '../views/components/modals.vue'),
    },
    {
        path: '/components/cards',
        name: 'cards',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-cards" */ '../views/components/cards.vue'),
    },
    {
        path: '/components/carousel',
        name: 'carousel',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-carousel" */ '../views/components/carousel.vue'),
    },
    {
        path: '/components/countdown',
        name: 'countdown',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-countdown" */ '../views/components/countdown.vue'),
    },
    {
        path: '/components/counter',
        name: 'counter',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-counter" */ '../views/components/counter.vue'),
    },
    {
        path: '/components/sweetalert',
        name: 'sweetalert',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-sweetalert" */ '../views/components/sweetalert.vue'),
    },
    {
        path: '/components/timeline',
        name: 'timeline',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-timeline" */ '../views/components/timeline.vue'),
    },
    {
        path: '/components/notifications',
        name: 'notifications',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-notifications" */ '../views/components/notifications.vue'),
    },
    {
        path: '/components/media-object',
        name: 'media-object',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-media-object" */ '../views/components/media-object.vue'),
    },
    {
        path: '/components/list-group',
        name: 'list-group',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-list-group" */ '../views/components/list-group.vue'),
    },
    {
        path: '/components/pricing-table',
        name: 'pricing-table',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-pricing-table" */ '../views/components/pricing-table.vue'),
    },
    {
        path: '/components/lightbox',
        name: 'lightbox',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "components-lightbox" */ '../views/components/lightbox.vue'),
    },


    //charts
    {
        path: '/charts',
        name: 'charts',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "charts" */ '../views/charts.vue'),
    },




    //auth
    {
        path: '/auth/cover-login',
        name: 'cover-login',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "forms-clipboard" */ '../views/auth/cover-login.vue'),
    },
    {
        path: '/auth/boxed-password-reset',
        name: 'boxed-password-reset',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "forms-clipboard" */ '../views/auth/boxed-password-reset.vue'),
    },
    {
        path: '/auth/boxed-signin',
        name: 'boxed-signin',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "forms-clipboard" */ '../views/auth/boxed-signin.vue'),
    },

    {
        path: '/auth/cover-password-reset',
        name: 'cover-password-reset',
        meta: {
            requiresAuth: true
        },
        component: () => import(/* webpackChunkName: "forms-clipboard" */ '../views/auth/cover-password-reset.vue'),
    },
    {
        path: '/:pathMatch(.*)*', // Vue Router v4 的通配符路径
        name: 'not-found',
        redirect: '/' // 重定向到首页，你也可以重定向到一个专门的404页面
    }

];

const router = createRouter({
    history: createWebHistory(),//createWebHistory(),
    //linkExactActiveClass: 'active',
    routes,
    /* scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition;
        } else {
            return { left: 0, top: 0 };
        }
    }, */
});
router.beforeEach((to, from, next) => {
    const store = useAppStore();
    console.log(to.meta.requiresAuth && !store.user);
    if (to.meta.requiresAuth && !store.user) {
        next({ name: 'login' });
    } else {
        next();
    }
});
router.afterEach((to, from, next) => {
    appSetting.changeAnimation();
});
export default router;
