/**
 * @Author: Kane Wang <wangkane@qq.com>
 * @Date: 2025-10-13 15:31:41
 * @LastEditors: Kane Wang
 * @LastModified: 2025-11-05 11:20:46
 * @FilePath: src/router/index.ts
 * @Description:
 *
 *               Copyright (c) 2025 by Kane All rights reserved
 */
import { createRouter, createWebHashHistory } from "vue-router";
import { type RouteRecordNormalized } from "vue-router";
// import index from "../layout/console/index.vue";

export declare interface SideBarRouteRecordNormalized extends RouteRecordNormalized
{
    hidden?: boolean;
}

const routes = [
    {
        path: "/",
        name: "root",
        redirect: "Overview",
        hidden: true,
    },
    {
        path: "/desktop",
        name: "Desktop",
        meta: {
            title: "工作台",
            icon: "house",
        },
        component: () => import( "../layout/console/Index.vue" ),
        children:[
            {
                path: "/overview",
                name: "Overview",
                meta: {
                    title: "总览",
                    icon: "house",
                },
                component: () => import( "@/views/console/desktop/Overview.vue" ),
            },
        ],
    },
    {
        path: "/data",
        name: "Data",
        meta: {
            title: "制度库管理",
            icon:"Collection",
        },
        component: () => import( "../layout/console/Index.vue" ),
        children:[
            {
                path: "/regulatory-management",
                name:"RegulatoryManagement",
                meta: {
                    title: "制度文件管理",
                    icon:"document",
                },
                component: ()=> import( "@/views/console/data/RegulatoryManagement.vue" ),
            },
            {
                path: "/department-management",
                name: "DepartmentManagement",
                meta:{
                    title: "组织机构管理",
                    icon: "OfficeBuilding",
                },
                component: ()=> import( "@/views/console/data/RegulatoryManagement.vue" ),
            },
            {
                path: "/new-regulatory",
                name: "NewRegulatory",
                meta: {
                    title: "测试用 - 新建",
                    icon: "OfficeBuilding",
                },
                hidden: false,
                component: () => import( "@/views/console/data/NewRegulatory.vue" ),
            },
            {
                path: "/upload-regulatory",
                name: "UploadRegulatory",
                meta: {
                    title: "测试用 - 查看制度",
                    icon: "OfficeBuilding",
                },
                hidden: false,
                component: () => import( "@/views/console/data/UploadRegulatory.vue" ),
            },
        ],
    },
];

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

// 工具函数
/* eslint-disable */
function hasOnlyChild( children: any ): boolean
{
    if ( !children )
    {
        return false;
    }

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

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

    return false;
}

export { router, hasOnlyChild };