import {
  getProfile
} from '@/api/login'
import {
  constantRouterMap
} from '@/config/router.config'
import {
  generatorDynamicRouter
} from '@/router/generator-routers'

const permission = {
  state: {
    menu: [],
  },
  mutations: {
    setMenu(state, meun) {
      state.menu = meun
    },
    SET_ROUTERS: (state, routers) => {
      state.addRouters = routers
      state.routers = constantRouterMap.concat(routers)
    },
  },
  getters: {
    getMenu(state) {
      return state.menu
    }
  },
  actions: {
    GenerateRoutes({
      commit
    }, data) {
      return new Promise((resolve, reject) => {
        const {
          token
        } = data
        generatorDynamicRouter(token).then(routers => {
          commit('setMenu', routers)
          commit('SET_ROUTERS', routers)
          resolve(routers)
        }).catch(e => {
          reject(e)
        })
      })
    }
  }
}

export default permission
