/*
 * @Author: Kane
 * @Date: 2023-02-28 01:22:48
 * @LastEditors: Kane
 * @FilePath: /task_schedule/src/router/index.js
 * @Description:
 *
 * Copyright (c) ${2022} by Kane, All Rights Reserved.
 */

import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
    {
        path: "/",
        name: "Root",
        redirect: "Login",
        hidden: true,
    },
    {
        path: "/login",
        name: "Login",
        hidden: true,
        component: async () => await import( "@/views/Login.vue" ),
    },
    // 桌面霸屏
    {
        path: "/desktop_archievement",
        name: "DesktopArchievement",
        hidden: true,
        component: async () => await import( "@/views/DesktopArchievement.vue" ),
    },
    // 工作台
    {
        path:"/console",
        name:"Console",
        meta: {
            title: "总览",
            icon: "house",
        },
        component: ()=> import( "../layout/Index.vue" ),
        children:[
            {
                path:"/desktop",
                name:"Desktop",
                meta: {
                    title:"工作台",
                    icon: "house",
                },
                component: ()=> import( "../views/Desktop.vue" ),
            },
        ],
    },
    //数据管理
    {
        path:"/data",
        name:"Data",
        meta:{
            title:"数据管理",
            icon: "document",
        },
        component: ()=> import( "../layout/Index.vue" ),
        children:[
            {
                path:"/telsaler_data",
                name:"TelsalerManagement",
                meta: {
                    title:"坐席管理",
                    icon: "user",
                },
                component: ()=> import( "../views/telsaler/TelsalerManagementView.vue" ),
            },
            {
                path: "/data_management",
                name: "DataManagement",
                meta: {
                    title: "数据管理",
                    icon: "document",
                },
                component: ()=> import( "../views/data/DataManagement.vue" ), 
            },
            {
                path:"/reward_management",
                name:"RewardManagement",
                meta: {
                    title:"奖励管理",
                    icon: "document",
                },
                component: ()=> import( "../views/RewardManagement.vue" ),
            },
        ],
    },
];

const router = createRouter(
    {
        history: createWebHashHistory(),
        routes,
    }
);

// 路由守卫
// router.beforeEach((to) =>
// {

// });

// 工具函数
function hasOnlyChild( children )
{
    if ( !children )
    {
        return false;
    }

    const routes = children.filter(( item )=>
    {
        return !item.hidden;
    });

    if ( routes.length === 1 )
    {
        return true;
    }

    return false;
}

export { router, hasOnlyChild };
