import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },

    {
        path: '/404',
        component: () =>
            import ('@/views/404'),
        hidden: true
    },

    {
        path: '/index',
        component: () =>
            import ('@/views/index'),
        hidden: true,

    },

    {
        path: '/',
        component: Layout,
        redirect: '/index',
        children: [{
            path: 'index',
            name: 'index',
            component: () =>
                import ('@/views/index/index'),
            meta: { title: '首页', icon: 'home' }
        }]
    },

    {
        path: '/system',
        component: Layout,
        redirect: '/system/per-manage',
        name: 'Example',
        meta: { title: '系统管理', icon: 'system-manage' },
        children: [{
                path: 'per-manage',
                name: 'Table',
                component: () =>
                    import ('@/views/system/per-manage/index'),
                meta: { title: '人员管理', icon: 'per-manage' }
            },
            {
                path: 'organization',
                name: 'Tree2',
                component: () =>
                    import ('@/views/system/organization/index'),
                meta: { title: '组织机构', icon: 'organization' }
            },
            {
                path: 'auth-manage',
                name: 'Tree3',
                component: () =>
                    import ('@/views/system/auth-manage/index'),
                meta: { title: '权限管理', icon: 'auth-manage' }
            },
            {
                path: 'security',
                name: 'Tree4',
                component: () =>
                    import ('@/views/system/security/index'),
                meta: { title: '安全机制', icon: 'security' }
            },
            {
                path: 'unit-info',
                name: 'Tree5',
                component: () =>
                    import ('@/views/system/unit-info/index'),
                meta: { title: '单位信息', icon: 'unit' }
            }

        ]
    },

    {
        path: '/user',
        component: Layout,
        redirect: '/user/account-manage',
        name: 'Nested2',
        meta: {
            title: '用户管理',
            icon: 'user-manage'
        },
        children: [{
                path: 'account-manage',
                component: () =>
                    import ('@/views/user/account-manage/index'), // Parent router-view
                name: 'Menu122',
                meta: { title: '账号管理', icon: 'account-manage' },

            },
            {
                path: 'log-manage',
                component: () =>
                    import ('@/views/user/log-manage/index'),
                name: 'Menu222',
                meta: { title: '日志管理', icon: 'log-manage' }
            }
        ]
    },


    {
        path: '/device',
        component: Layout,
        redirect: '/device/camera',
        name: 'Nested22',
        meta: {
            title: '设备管理',
            icon: 'device-manage'
        },
        children: [{
                path: 'camera2',
                component: () =>
                    import ('@/views/device/camera/index'), // Parent router-view
                name: 'Menu12',
                meta: { title: '摄像头', icon: 'camera' },

            },
            {
                path: 'guard',
                component: () =>
                    import ('@/views/device/guard/index'),
                name: 'Menu22',
                meta: { title: '周界防范', icon: 'guard' }
            }
        ]
    },


    {
        path: '/patrol',
        component: Layout,
        redirect: '/patrol/patrol-point',
        name: 'patrol-manage',
        meta: {
            title: '巡检管理',
            icon: 'patrol-manage'
        },
        children: [{
                path: 'patrol-point',
                component: () =>
                    import ('@/views/patrol/patrol-point/index'), // Parent router-view
                name: 'Menu1',
                meta: { title: '巡检点', icon: 'patrol-point' },

            },
            {
                path: 'patrol-route',
                component: () =>
                    import ('@/views/patrol/patrol-route/index'),
                name: 'Menu2',
                meta: { title: '巡检路线', icon: 'patrol-route' }
            },
            {
                path: 'team',
                component: () =>
                    import ('@/views/patrol/team/index'),
                name: 'Menu3',
                meta: { title: '班组人员', icon: 'team' }
            },
            {
                path: 'elect-partol',
                component: () =>
                    import ('@/views/patrol/elect-partol/index'),
                name: 'Menu4',
                meta: { title: '电子巡更', icon: 'elect' }
            },
            {
                path: 'partol-plan',
                component: () =>
                    import ('@/views/patrol/partol-plan/index'),
                name: 'Menu5',
                meta: { title: '巡检计划', icon: 'patrol-plan' }
            }
        ]
    },
    {
        path: '/alarm',
        component: Layout,
        redirect: '/alarm/alarm-log',
        name: 'Nested111',
        meta: {
            title: '告警中心',
            icon: 'alarm'
        },
        children: [{
                path: 'alarm-log',
                component: () =>
                    import ('@/views/alarm/alarm-log/index'), // Parent router-view
                name: 'Menu13',
                meta: { title: '告警记录', icon: 'alarm-log' },

            },
            {
                path: 'alarm-task',
                component: () =>
                    import ('@/views/alarm/alarm-task/index'),
                name: 'Menu23',
                meta: { title: '任务中心', icon: 'alarm-task' }
            },

        ]
    },









    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router