import { Merchant, Investor, Agent } from './updateMenu'
import AllPages from '../../pages.json'
let menu = [
  {
    pagePath: '/pages/index/index',
    iconPath: '/static/tabbar/home_icon.png',
    selectedIconPath: '/static/tabbar/home_active.png',
    text: '首页'
  },
  {
    pagePath: '/pages/ai/chat',
    iconPath: '/static/tabbar/news_icon.png',
    selectedIconPath: '/static/tabbar/news_active.png',
    text: '管家在线'
  },
  {
    pagePath: '/pages/me/index',
    iconPath: '/static/tabbar/news_icon.png',
    selectedIconPath: '/static/tabbar/news_active.png',
    text: '我的'
  }
]
export function setTabBar(res: any) {
  const pages = getCurrentPages()
  const currentPage: any = pages[pages.length - 1]
  if (currentPage) {
    const tabBar = currentPage?.getTabBar ? currentPage?.getTabBar() : null
    let list = res?.companyConfig?.config_value?.menu?.map((i: any) => ({
      ...i,
      iconPath: i.iconPath?.[0]?.url,
      selectedIconPath: i.selectedIconPath?.[0]?.url
    }))
    list.splice(res?.companyConfig?.config_value?.menu?.length / 2, 0, {
      pagePath: '/pages/ai/index',
      iconPath:
        'https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png',
      selectedIconPath:
        'https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png',
      text: '管家在线'
    })
    getApp().globalData.menuList = list || menu
    console.log('getApp().globalData', getApp().globalData, list)
    if (tabBar) {
      tabBar.setData({
        list: list || menu
      })
    }
  }
  console.log('App.globalData.selectedOrg', res?.companyConfig?.config_value?.menu)
}
