
// 客户页面
const mainPages = [
  {
    title: '首页',
    page: 'pages/index/index',
    isIndex: true,
  },
  {
    title: '搜索',
    page: 'pages/search/search',
  },
  {
    title: '搜索结果',
    page: 'pages/searchResult/searchResult',
  },
  {
    title: '商铺详情',
    page: 'pages/details/foodDetails/foodDetails',
  },
  {
    title: '景点详情',
    page: 'pages/details/mjDetails/sceneryDetails',
  },
  {
    title: '订单',
    page: 'pages/PayOrder/index',
  },
  {
    title: '联系我们',
    page: 'pages/MineUserAll/ContactMe/index',
  },
  {
    title: '我的收藏',
    page: 'pages/MineUserAll/Collect/index',
  },
  {
    title: '协议声明',
    page: 'pages/MineUserAll/Rules/index',
  },
  {
    title: '退款申请',
    page: 'pages/MineUserAll/RefundMoney/index',
  },
  {
    title: '确认退款',
    page: 'pages/MineUserAll/RefundMoney/CheckRefund/index',
  },
  {
    title: '我的订单',
    page: 'pages/MineUserAll/AllOrder/index',
  },
  {
    title: '套餐核销',
    page: 'pages/TobeShop/index',
  },
];

// 商户管理页面shop/pages/spread/spreadIndex
const shopPages = [
  {
    title: '商铺管理',
    page: 'pages/spread/spreadIndex',
    isIndex: true,
  },
];

// 民宿管理页面hotel/pages/landlord/landlord
const hotelPages = [
  {
    title: '民宿管理',
    page: 'pages/landlord/landlord',
    isIndex: true,
  },
];

// 所有的页面
const routes = mainPages.concat(shopPages.map(x => ({...x, root: 'shop'})))
                        .concat(hotelPages.map(x => ({...x, root: 'hotel'})))

// 主包
const pages = mainPages.map(x => x.page);

// 分包
const subPages = routes.reduce((acc, route) => {
  if (!route.root) return acc;

  const pgs = acc[route.root] || []

  return {
    ...acc,
    [route.root]: pgs.concat(route.page)
  }
}, {})

const subPackages = Object.keys(subPages).map((key) => {
  return {
    root: key,
    pages: subPages[key]
  }
})

// 获取路径对应页面
function getPageBy(path) {
  return routes.filter(x => path.indexOf(x.page) > -1)[0]
}

// 获取角色首页
function getIndexPageOf(role) {
  if (role === 'person') {
    return routes.filter(x => !x.root && x.isIndex)[0]
  }

  return routes.filter(x => x.root === role && x.isIndex)[0]
}

// eslint-disable-next-line import/no-commonjs
module.exports = {
  routes,
  pages,
  subPackages,
  getPageBy,
  getIndexPageOf
}
