import type { RouteRecordRaw } from 'vue-router'

const pageTitle = (name: string): string => {
    return `pagesTitle.${name}`
}
/**
 * 后台基础路由路径
 */
export const adminBaseRoutePath = '/admin'
export const adminBaseRoute = {
    path: adminBaseRoutePath,
    name: 'admin',
    component: () => import('@/layouts/admin/index.vue'),
    // 直接重定向到 loading 路由
    redirect: adminBaseRoutePath + '/loading',
    meta: {
        title: `pagesTitle.admin`
    },
    children: [
        {
            path: 'loading/:to?',
            name: 'adminMainLoading',
            component: () => import('@/layouts/common/components/loading.vue'),
            meta: {
                title: `pagesTitle.loading`
            }
        },
        {
            path: 'businessUserRouter',
            name: '业务管理员页面',
            meta: {
                title: pageTitle('businessUser'),
                icon: 'ep:management',
                alwaysShow: true
            },
            children: [
                {
                    path: 'eventView',
                    component: () => import('@/views/pqs/voltageSags/sagGovern/businessUser/event/eventView.vue'),
                    name: '暂降事件查看页面',
                    meta: {
                        title: pageTitle('router.eventView')
                    }
                },
                {
                    path: 'productLine',
                    component: () => import('@/views/pqs/voltageSags/sagGovern/businessUser/productLine/index.vue'),
                    name: '生产线查看页面',
                    meta: {
                        title: pageTitle('router.eventView')
                    }
                },
                {
                    path: 'machine',
                    component: () => import('@/views/pqs/voltageSags/sagGovern/businessUser/machine/index.vue'),
                    name: '终端查看页面',
                    meta: {
                        title: pageTitle('router.eventView')
                    }
                }
            ]
        },
        {
            path: 'sagGovernScheme',
            name: '暂降治理评估方案',
            meta: {
                title: pageTitle('sagGovernScheme'),
                icon: 'ep:management',
                alwaysShow: true
            },
            children: [
                {
                    path: 'schemeCalc',
                    component: () => import('@/views/pqs/voltageSags/sagGovern/scheme/schemeCalc/index.vue'),
                    name: '治理评估页面',
                    meta: {
                        title: pageTitle('router.schemeCalc')
                    }
                },
                {
                    path: 'schemeHistory',
                    component: () => import('@/views/pqs/voltageSags/sagGovern/scheme/history/index.vue'),
                    name: '治理方案结果详情',
                    meta: {
                        title: pageTitle('router.schemeHistory')
                    }
                }
            ]
        },
        {
            path: '/bpm',
            name: 'bpm',
            meta: {
                hidden: true
            },
            children: [
                {
                    path: 'formEdit',
                    component: () => import('@/views/system/bpm/form/editor/index.vue'),
                    name: 'BpmFormEditor',
                    meta: {
                        title: pageTitle('router.formEdit')
                    }
                },
                {
                    path: 'modelEdit',
                    component: () => import('@/views/system/bpm/model/editor/index.vue'),
                    name: 'BpmModelEditor',
                    meta: {
                        title: pageTitle('router.modelEdit')
                    }
                },
                {
                    path: 'instanceDetail',
                    component: () => import('@/views/system/bpm/processInstance/detail/index.vue'),
                    name: 'BpmProcessInstanceDetail',
                    meta: {
                        title: pageTitle('router.instanceDetail')
                    }
                },
                {
                    path: 'ProgramReviewInter',
                    component: () =>
                        import('@/views/pqs/supervise/interfere/components/normalizationManager/programReview.vue'),
                    name: 'ProgramReview',
                    meta: {
                        title: pageTitle('router.programReview')
                    }
                },
                {
                    path: 'effectProblem',
                    component: () => import('@/views/pqs/supervise/plan/components/effectProblem/index.vue'),
                    name: 'PlanEffectProblem',
                    meta: {
                        title: pageTitle('router.effectProblem')
                    }
                }
                // {
                //     path: 'manager/model/edit',
                //     component: () => import('@/views/bpm/model/editor/index.vue'),
                //     name: 'BpmModelEditor',
                //     meta: {
                //         noCache: true,
                //         hidden: true,
                //         canTo: true,
                //         title: '设计流程',
                //         activeMenu: '/bpm/manager/model'
                //     }
                // },
                // {
                //     path: 'manager/definition',
                //     component: () => import('@/views/bpm/definition/index.vue'),
                //     name: 'BpmProcessDefinition',
                //     meta: {
                //         noCache: true,
                //         hidden: true,
                //         canTo: true,
                //         title: '流程定义',
                //         activeMenu: '/bpm/manager/model'
                //     }
                // },
            ]
        },
        {
            path: 'division',
            name: '谐波责任划分页面',
            meta: {
                title: pageTitle('division'),
                icon: 'ep:management',
                alwaysShow: true
            },
            children: [
                {
                    path: 'aListOfLoadData',
                    component: () =>
                        import('@/views/pqs/harmonicMonitoring/detailed/division/components/aListOfLoadData.vue'),
                    name: '用采数据列表页面',
                    meta: {
                        title: pageTitle('router.aListOfLoadData')
                    }
                },
                {
                    path: 'compute',
                    component: () => import('@/views/pqs/harmonicMonitoring/detailed/division/components/compute.vue'),
                    name: '贡献度计算页面',
                    meta: {
                        title: pageTitle('router.compute')
                    }
                },
                {
                    path: 'detail',
                    component: () => import('@/views/pqs/harmonicMonitoring/detailed/division/components/detail.vue'),
                    name: 'detail',
                    meta: {
                        title: pageTitle('router.detail')
                    }
                }
            ]
        },
        {
            path: 'runManage',
            name: '二级评估',
            meta: {
                title: pageTitle('runManage'),
                icon: 'ep:management',
                alwaysShow: true
            },
            children: [
                {
                    path: 'addUser',
                    component: () => import('@/views/pqs/runManage/assessment/components/uese/form.vue'),
                    name: '新增评估用户',
                    meta: {
                        title: pageTitle('router.addUser')
                    }
                }
            ]
        },
        {
            path: 'cockpit',
            name: '项目管理',
            meta: {
                title: pageTitle('runManage'),
                icon: 'ep:management',
                alwaysShow: true
            },
            children: [
                {
                    path: 'popup',
                    component: () => import('@/views/pqs/cockpit/setUp/components/popup.vue'),
                    name: '新增项目',
                    meta: {
                        title: pageTitle('router.popup')
                    }
                },
                {
                    path: 'view',
                    component: () => import('@/views/pqs/cockpit/setUp/components/view.vue'),
                    name: '预览项目',
                    meta: {
                        title: pageTitle('router.view')
                    }
                }
            ]
        },
        {
            path: 'BusinessAdministrator/TerminalManagement',
            name: '变压器策略',
            meta: {
                title: pageTitle('runManage'),
                icon: 'ep:management',
                alwaysShow: true
            },
            children: [
                {
                    path: 'addLedger',
                    component: () =>
                        import('@/views/pqs/business/terminal/transformerStrategy/components/addLedger.vue'),
                    name: '变压器台账配置',
                    meta: {
                        title: pageTitle('router.addLedger')
                    }
                }
            ]
        },
        {
            path: '/boX',
            name: 'boX',
            component: () => import('@/components/echarts/boX.vue'),
            meta: {
                title: pageTitle('boX')
            }
        }
        /*{
            path: '/bpm',
            name: 'bpm',
            meta: {
                hidden: true
            },
            children: [
                {
                    path: 'programReview',
                    component: () => import('@/views/pqs/supervise/interfere/components/normalizationManager/programReview.vue'),
                    name: 'programReview',
                    meta: {
                        title: pageTitle('router.programReview')
                    }
                },{
                    path: 'projectTreat',
                    component: () => import('@/views/pqs/supervise/interfere/components/normalizationManager/projectTreat.vue'),
                    name: 'projectTreat',
                    meta: {
                        title: pageTitle('router.projectTreat')
                    }
                },


            ]
        },*/
    ]
}

/*
 * 静态路由
 * 自动加载 ./static 目录的所有文件，并 push 到以下数组
 */
const staticRoutes: Array<RouteRecordRaw> = [
    adminBaseRoute,
    {
        path: '/',
        redirect: to => {
            return {
                name: 'adminMainLoading'
            }
        }
    },
    {
        // 管理员登录页 - 不放在 adminBaseRoute.children 因为登录页不需要使用后台的布局
        path: '/login',
        name: 'login',
        component: () => import('@/views/user/login.vue'),
        meta: {
            title: pageTitle('login')
        }
    },
    {
        path: '/:path(.*)*',
        redirect: '/404'
    },
    {
        path: '/404',
        name: 'notFound',
        component: () => import('@/views/common/error/404.vue'),
        meta: {
            title: pageTitle('notFound') // 页面不存在
        }
    },
    {
        path: '/previewFile',
        name: 'previewFile',
        component: () => import('@/components/PreviewFile/index.vue'),
        meta: {
            title: pageTitle('previewFile')
        }
    },

    {
        // 后台找不到页面了-可能是路由未加载上
        path: adminBaseRoutePath + '/:path(.*)*',
        redirect: to => {
            return {
                name: 'adminMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query
                    })
                }
            }
            
        }
    }
]

export default staticRoutes
