import session from '@/lib/session'

export default {
  state: {
    index: '0',
    isCollapse: false,
    menus: [],
  },
  mutations: {
    // 初始化菜单
    InitNavMenu(state, payload) {
      if (payload != null) {
        session.Set('menus', JSON.stringify(payload), true)
        session.Set('isCollapse', 'false', false)
      }
      const menus = JSON.parse(session.Get('menus', true))
      menus.forEach((item) => {
        if (item.name == 'R-User') {
          const visibleChildren = item.children.filter((el) => el.show)
          if (visibleChildren.length === 1 && visibleChildren[0].name === 'R-UserList') {
            console.log(visibleChildren[0].btns['R-UserList-Search'].show)
            if (visibleChildren[0].btns['R-UserList-Search'].show === false) {
              item.show = false
            }
          }
        }
      })
      state.menus = JSON.parse(session.Get('menus', true))
      console.log(state.menus, '---')
      state.isCollapse = session.Get('isCollapse', false) == 'true' ? true : false
    },

    // 菜单切换
    SetCollapse(state, payload) {
      state.isCollapse = payload
      session.Set('isCollapse', payload)
    },
  },
}
