export interface RouterType {
  path:string,
  name:string,
  addr?:string,
  icon?:string,
  children?:RouterType[]
}

export const buildTree =(routes: RouterType[]): RouterType[]=> {
  const map: { [key: string]: RouterType } = {}
  const tree: RouterType[] = []
  routes.forEach(route => {
    map[route.path] = { ...route, children: [] }
  })

  for (const route of routes) {
    const parentPath = route.path.substring(0, route.path.lastIndexOf('/'))
    if (map[parentPath]) {
      map[parentPath].children?.push(map[route.path])
    } else {
      tree.push(map[route.path])
    }
  }

  return tree
}

export const routeList:RouterType[] = [
  {
    path: 'zhdpgl',
    name: '智慧大屏管理',
    icon: 'Location'
  },
  {
    path: 'zhdpgl/yqzl',
    name: '园区总览',
    icon: 'Location',
  },
  {
    path: 'zhdpgl/yqzl/yqjs',
    name: '园区总览-园区介绍',
    icon: 'Location',
    addr: 'zhdpgl/yqzl/yqjs'
  },
  {
    path: 'zhdpgl/yqzl/yqaf',
    name: '园区总览-园区安防',
    icon: 'Location',
    addr: 'zhdpgl/yqzl/yqaf'
  },
  {
    path: 'zhdpgl/yqzl/yqxf',
    name: '园区总览-园区消防',
    icon: 'Location',
    addr: 'zhdpgl/yqzl/yqxf'
  },
  {
    path: 'zhdpgl/yqzl/yqnh',
    name: '园区总览-园区能耗',
    icon: 'Location',
    addr: 'zhdpgl/yqzl/yqnh'
  },



  {
    path: 'zhdpgl/zhaf',
    name: '智慧安防',
    icon: 'Location',
  },

  {
    path: 'zhdpgl/zhaf/ssjk',
    name: '智慧安防-实时监控',
    icon: 'Location',
    addr: 'zhdpgl/zhaf/ssjk'
  },

  {
    path: 'zhdpgl/zhaf/jrbjlb',
    name: '智慧安防-今日报警列表',
    icon: 'Location',
    addr: 'zhdpgl/zhaf/jrbjlb'
  },

  {
    path: 'zhdpgl/zhaf/ssbjtj',
    name: '智慧安防-实时报警统计',
    icon: 'Location',
    addr: 'zhdpgl/zhaf/ssbjtj'
  },

  {
    path: 'zhdpgl/zhaf/sbdwlb',
    name: '智慧安防-设备点位列表',
    icon: 'Location',
    addr: 'zhdpgl/zhaf/sbdwlb'
  },
  {
    path: 'zhdpgl/zhaf/sjzx',
    name: '智慧安防-事件中心',
    icon: 'Location',
    addr: 'zhdpgl/zhaf/sjzx'
  },
  {
    path: 'zhdpgl/zhaf/sjtjzx',
    name: '智慧安防-事件统计中心',
    icon: 'Location',
    addr: 'zhdpgl/zhaf/sjtjzx'
  },


  {
    path: 'zhdpgl/zhnh',
    name: '智慧能耗',
    icon: 'Location',
  },
  {
    path: 'zhdpgl/zhnh/sbbj',
    name: '智慧能耗-设备报警',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/sbbj'
  },
  {
    path: 'zhdpgl/zhnh/sbzxzt',
    name: '智慧能耗-设备在线状态',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/sbzxzt'
  },
  {
    path: 'zhdpgl/zhnh/sbfjc',
    name: '智慧能耗-水泵房监测',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/sbfjc'
  },
  {
    path: 'zhdpgl/zhnh/sblb',
    name: '智慧能耗-设备列表',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/sblb'
  },
  {
    path: 'zhdpgl/zhnh/sjtjzx',
    name: '智慧能耗-事件统计中心',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/sjtjzx'
  },

  {
    path: 'zhdpgl/zhnh/zhnhs',
    name: '水',
    icon: 'Location',
  },

  {
    path: 'zhdpgl/zhnh/zhnhs/dyysl',
    name: '智慧能耗-当月用水量',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhs/dyysl'
  },

  {
    path: 'zhdpgl/zhnh/zhnhs/bndysl',
    name: '智慧能耗-本年度用水量',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhs/bndysl'
  },
  {
    path: 'zhdpgl/zhnh/zhnhs/nhjgs',
    name: '智慧能耗-能耗结构（水）',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhs/nhjgs'
  },
  {
    path: 'zhdpgl/zhnh/zhnhs/fxyszb',
    name: '智慧能耗-分项用水占比',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhs/fxyszb'
  },
  {
    path: 'zhdpgl/zhnh/zhnhs/qyyshz',
    name: '智慧能耗-企业用水汇总',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhs/qyyshz'
  },
  {
    path: 'zhdpgl/zhnh/zhnhs/ystjfx',
    name: '智慧能耗-用水统计分析',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhs/ystjfx'
  },


  {
    path: 'zhdpgl/zhnh/zhnhd',
    name: '电',
    icon: 'Location',
  },
  {
    path: 'zhdpgl/zhnh/zhnhd/dyydl',
    name: '智慧能耗-当月用电量',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhd/dyydl'
  },

  {
    path: 'zhdpgl/zhnh/zhnhd/bndydl',
    name: '智慧能耗-本年度用电量',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhd/bndydl'
  },
  {
    path: 'zhdpgl/zhnh/zhnhd/nhjgd',
    name: '智慧能耗-能耗结构（电）',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhd/nhjgd'
  },
  {
    path: 'zhdpgl/zhnh/zhnhd/fxydzb',
    name: '智慧能耗-分项用电占比',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhd/fxydzb'
  },
  {
    path: 'zhdpgl/zhnh/zhnhd/qyydhz',
    name: '智慧能耗-企业用电汇总',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhd/qyydhz'
  },
  {
    path: 'zhdpgl/zhnh/zhnhd/ydtjfx',
    name: '智慧能耗-用电统计分析',
    icon: 'Location',
    addr: 'zhdpgl/zhnh/zhnhd/ydtjfx'
  },


  {
    path: 'zhdpgl/zhxf',
    name: '智慧消防',
    icon: 'Location',
  },
  {
    path: 'zhdpgl/zhxf/jrsb',
    name: '智慧消防-接入设备',
    icon: 'Location',
    addr: 'zhdpgl/zhxf/jrsb'
  },
  {
    path: 'zhdpgl/zhxf/ssjk',
    name: '智慧消防-实时监控',
    icon: 'Location',
    addr: 'zhdpgl/zhxf/ssjk'
  },
  {
    path: 'zhdpgl/zhxf/sbdwlb',
    name: '智慧消防-设备点位列表',
    icon: 'Location',
    addr: 'zhdpgl/zhxf/sbdwlb'
  },
  {
    path: 'zhdpgl/zhxf/ystjfx',
    name: '智慧消防-用水统计分析',
    icon: 'Location',
    addr: 'zhdpgl/zhxf/ystjfx'
  },
  {
    path: 'zhdpgl/zhxf/ssbjtj',
    name: '智慧消防-实时报警统计',
    icon: 'Location',
    addr: 'zhdpgl/zhxf/ssbjtj'
  },
  {
    path: 'zhdpgl/zhxf/bjtj',
    name: '智慧消防-报警统计',
    icon: 'Location',
    addr: 'zhdpgl/zhxf/bjtj'
  },


  {
    path: 'zhdpgl/zhdg',
    name: '智慧灯杆',
    icon: 'Location',
  },
  {
    path: 'zhdpgl/zhdg/dgzm',
    name: '智慧灯杆-灯杆照明',
    icon: 'Location',
    addr: 'zhdpgl/zhdg/dgzm'
  },
  {
    path: 'zhdpgl/zhdg/wg',
    name: '智慧灯杆-网关',
    icon: 'Location',
    addr: 'zhdpgl/zhdg/wg'
  },
  {
    path: 'zhdpgl/zhdg/yjhj',
    name: '智慧灯杆-一键呼叫',
    icon: 'Location',
    addr: 'zhdpgl/zhdg/yjhj'
  },
  {
    path: 'zhdpgl/zhdg/dpfb',
    name: '智慧灯杆-大屏发布',
    icon: 'Location',
    addr: 'zhdpgl/zhdg/dpfb'
  },


  {
    path: 'zhdpgl/zhtc',
    name: '智慧停车',
    icon: 'Location',
  },
  {
    path: 'zhdpgl/zhtc/drjccl',
    name: '智慧停车-当日进出车辆',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/drjccl'
  },
  {
    path: 'zhdpgl/zhtc/byjccl',
    name: '智慧停车-本月进出车辆',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/byjccl'
  },
  {
    path: 'zhdpgl/zhtc/cllxjg',
    name: '智慧停车-车辆类型结构',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/cllxjg'
  },
  {
    path: 'zhdpgl/zhtc/clzylfx',
    name: '智慧停车-车辆占用率分项',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/clzylfx'
  },
  {
    path: 'zhdpgl/zhtc/ryqk',
    name: '智慧停车-人员情况',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/ryqk'
  },
  {
    path: 'zhdpgl/zhtc/yqrygl',
    name: '智慧停车-园区人员管理',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/yqrygl'
  },
  {
    path: 'zhdpgl/zhtc/ryll',
    name: '智慧停车-人员流量',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/ryll'
  },
  {
    path: 'zhdpgl/zhtc/kll',
    name: '智慧停车-客流量',
    icon: 'Location',
    addr: 'zhdpgl/zhtc/kll'
  },





  {
    path: 'zhld',
    name: '智慧路灯',
    icon: 'Location',
  },
  {
    path: 'zhld/yqzl',
    name: '园区总览2',
    icon: 'Location',
    addr: 'zhld/yqzl'
  },
  {
    path: 'zhld/zhaf',
    name: '智慧安防2',
    icon: 'Location',
    addr: 'zhld/zhaf'
  },
  {
    path: 'zhld/zhnh',
    name: '智慧能耗2',
    icon: 'Location',
    addr: 'zhld/zhnh'
  },
  {
    path: 'zhld/zhxf',
    name: '智慧消防2',
    icon: 'Location',
    addr: 'zhld/zhxf'
  },
  {
    path: 'zhld/zhdg',
    name: '智慧灯杆2',
    icon: 'Location',
    addr: 'zhld/zhdg'
  },
  {
    path: 'zhld/zhtc',
    name: '智慧停车2',
    icon: 'Location',
    addr: 'zhld/zhtc'
  },
  {
    path: 'zhhj',
    name: '智慧环境',
    icon: 'Location',
  },
  {
    path: 'zhhj/ssjc',
    name: '实时监测',
    icon: 'Location',
    addr: 'zhhj/ssjc'
  },
  {
    path: 'zhhj/sjcx',
    name: '数据查询',
    icon: 'Location',
    addr: 'zhhj/sjcx'
  },
  {
    path: 'zhhj/bjcx',
    name: '报警查询',
    icon: 'Location',
    addr: 'zhhj/bjcx'
  },
  {
    path: 'zhhj/bjjbpz',
    name: '报警级别配置',
    icon: 'Location',
    addr: 'zhhj/bjjbpz'
  },
  {
    path: 'zhhj/bjld',
    name: '报警联动',
    icon: 'Location',
    addr: 'zhhj/bjld'
  },
  {
    path: 'zhhj/ccclpz',
    name: '存储策略配置',
    icon: 'Location',
    addr: 'zhhj/ccclpz'
  },
  {
    path: 'zhhj/pzpcyz',
    name: '配置偏差阈值',
    icon: 'Location',
    addr: 'zhhj/pzpcyz'
  },
]
export const useDynamicRoutes: () => RouterType[] = () => {
  routeList.forEach(item => {
    item.addr = `views/${item.addr}.vue`
  })
  return [
    ...routeList
  ]
}
