
const routes = [

  /**********************************
   *  Tab 页面
   *********************************/
  {
    name: '首页',
    page: 'pages/index/index',
    pkg: 'main',
    isTab: true,
    type: 'main',
    shortcut: {
      chat: false,
      consultant: true,
    },
    // auth: ['phone', 'avatar']
  },
  // {
  //   name: '视频',
  //   page: 'pages/video/index',
  //   pkg: 'main',
  //   isTab: true,
  //   type: 'video',
  // },
  {
    name: '消息',
    page: 'pages/chat/index',
    pkg: 'main',
    isTab: true,
    type: 'chat',
    auth: ['page', 'avatar'],
  },
  {
    name: '我是',
    page: 'pages/mine/index',
    pkg: 'main',
    isTab: true,
    type: 'mine',
    auth: ['page', 'avatar'],
  },

  // 聊天
  {
    name: '聊天',
    page: 'pages/chat/chatDetail/index',
    pkg: 'main',
    type: 'chat',
    auth: ['phone', 'avatar'],
  },

  // /********************************
  //  * 项目相关
  //  *******************************/
  {
    name: '定位',
    page: 'pages/index/location/index',
    pkg: 'main',
    type: 'other',
  },
  {
    name: '帮我找房',
    page: 'pages/index/helpToFindHouse/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '地图找房',
    page: 'pages/index/findHouseFromMap/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '楼盘搜索',
    page: 'pages/index/buildingSearch/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '楼盘列表',
    page: 'pages/index/buildingList/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '楼盘详情',
    page: 'pages/index/buildingDetail/index',
    pkg: 'main',
    type: 'building',
    // auth: ['phone', 'avatar'],
    shortcut: {
      chat: false,
      consultant: true,
    },
  },
  {
    name: '全景看房',
    page: 'pages/index/panoramaChecking/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '楼盘信息',
    page: 'pages/index/buildingInfo/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '围观记录',
    page: 'pages/index/buildingViewsRecords/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '置业顾问',
    page: 'pages/index/buildingPropertyConsultant/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '相册图片',
    page: 'pages/index/buildingPictures/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '报备规则',
    page: 'pages/index/buildingRules/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '一键带看',
    page: 'pages/index/buildingTakeLook/index',
    pkg: 'main',
    type: 'building',
    auth: ['phone', 'avatar'],
  },
  {
    name: '项目动态',
    page: 'pages/index/buildingDynamic/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '周边设施',
    page: 'pages/index/buildingAround/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '品牌列表',
    page: 'pages/index/brandList/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '品牌专题',
    page: 'pages/index/brandDetail/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '增值服务',
    page: 'pages/index/addedValueService/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '活动列表',
    page: 'pages/index/activityList/index',
    pkg: 'main',
    type: 'activity',
    // auth: ['phone', 'avatar'],
  },
  {
    name: '活动详情',
    page: 'pages/index/activityDetail/index',
    pkg: 'main',
    type: 'activity',
    auth: ['phone', 'avatar'],
  },
  {
    name: '特价房',
    page: 'pages/index/specialPriceHouse/index',
    pkg: 'main',
    type: 'building',
    auth: ['phone', 'avatar'],
  },
  {
    name: '免责声明',
    page: 'pages/index/disclaimer/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '康养',
    page: 'pages/index/recovered/index',
    pkg: 'main',
    type: 'other',
  },
  {
    name: '文旅商办',
    page: 'pages/index/culturalAndBusiness/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '资讯',
    page: 'pages/index/newsList/index',
    pkg: 'main',
    type: 'news',
  },
  {
    name: '资讯详情',
    page: 'pages/index/newsDetail/index',
    pkg: 'main',
    type: 'news',
  },
  {
    name: '购房百科',
    page: 'pages/index/encyclopediasOfBuyHouse/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '百科详情',
    page: 'pages/index/encyDetail/index',
    pkg: 'main',
    type: 'building',
  },
  {
    name: '课程详情',
    page: 'pages/index/courseDetail/index',
    pkg: 'main',
    type: 'curriculum',
  },

  //视频
  {
    name: '直播活动',
    page: 'pages/video/liveDetail/index',
    pkg: 'main',
    type: 'video',
  },
  {
    name: '视频详情',
    page: 'pages/video/videoDetail/index',
    pkg: 'main',
    type: 'video',
  },

  // 我的
  {
    name: '我的推广码',
    page: 'pages/mine/myRecommendCode/index',
    pkg: 'main',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '房贷计算器',
    page: 'pages/mine/mortgageCalc/index',
    pkg: 'main',
    type: 'other',
  },
  {
    name: '基本信息',
    page: 'pages/mine/userInfo/index',
    pkg: 'main',
    type: 'mine',
    auth: ['phone', 'avatar'],
  },
  {
    name: '成为驻场管理',
    page: 'pages/mine/toBeManager/index',
    pkg: 'main',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '成为合伙人',
    page: 'pages/mine/toBeAgent/index',
    pkg: 'main',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '我的分享',
    page: 'pages/mine/myShare/index',
    pkg: 'main',
    type: 'mine',
  },
  {
    name: '我的课堂',
    page: 'pages/mine/myCourse/index',
    pkg: 'main',
    type: 'curriculum',
    // auth: ['phone'],
  },
  {
    name: '我的活动',
    page: 'pages/mine/myActivity/index',
    pkg: 'main',
    type: 'activity',
  },
  {
    name: '我的客户',
    page: 'pages/mine/myCustomer/index',
    pkg: 'main',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '客户详情',
    page: 'pages/mine/myCustomerDetail/index',
    pkg: 'main',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '我的收藏',
    page: 'pages/mine/myCollect/index',
    pkg: 'main',
    type: 'mine',
  },
  {
    name: '合作渠道',
    page: 'pages/channel/partnerChannel/index',
    pkg: 'subpackages',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '添加客户',
    page: 'pages/mine/addCustomer/index',
    pkg: 'main',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '驻场管理',
    page: 'pages/marketing/residentManager/index',
    pkg: 'subpackages',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '确认到访',
    page: 'pages/marketing/sureVisit/index',
    pkg: 'subpackages',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '变更交易节点',
    page: 'pages/marketing/changeVisit/index',
    pkg: 'subpackages',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '盘客工具',
    page: 'pages/consultant/statCustomer/index',
    pkg: 'subpackages',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '客户信息',
    page: 'pages/mine/customerDetail/index',
    pkg: 'main',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '客户分析',
    page: 'pages/consultant/customerAnalyse/index',
    pkg: 'subpackages',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '个人主页',
    page: 'pages/consultant/myHomepage/index',
    pkg: 'subpackages',
    type: 'mine',
    // auth: ['phone'],
  },
  {
    name: '意见反馈',
    page: 'pages/mine/feedBack/index',
    pkg: 'main',
    type: 'mine',
  },
  {
    name: '全景图',
    page: 'pages/index/webview/index',
    pkg: 'main',
    type: 'other',
  },

]

/**
 * 获取 app pages 列表
 */
function getPages() {
  const grp = routes.reduce((g, r) => {
    const { pkg, page } = r
    const pg = g[pkg] || []
    
    return Object.assign(g, {
      [`${pkg}`]: pg.concat(page),
    })
  }, {});

  const pages = grp.main;
  const subPackages = Object.keys(grp).filter(x => x !== 'main').reduce(((pkg, key) => {
    return pkg.concat({
      root: key,
      pages: grp[key],
    })
  }),[])


  return {
    pages,
    subPackages,
  }
}

// eslint-disable-next-line import/no-commonjs
module.exports = {
  routes,
  getPages,
};
