import { globalApi } from '@/api'

// 获取菜单数据
const GET_MEUMS = 'GET_MEUMS'

// 显示设置快捷菜单
const SHOW_EDIT_MENUS = 'SHOW_EDIT_MENUS'

// 隐藏设置快捷菜单
const HIDE_EDIT_MENUS = 'HIDE_EDIT_MENUS'

// 边侧菜单
const SIDEBAR_UNFOLD = 'SIDEBAR_UNFOLD'

const state = {
  menus: [],
  editMenus: false,
  sidebarUnfold: false // false:边侧菜单收缩, true:边侧菜单展开
}

const actions = {
  async getMenus ({
    commit, dispatch
  }, parmas) {
    let res = await globalApi.getMenus(parmas)
    let menus = res.data.data
    commit(GET_MEUMS, menus)
  },
  showEditMenus ({commit}) {
    commit(SHOW_EDIT_MENUS, true)
  },
  hideEditMenus ({commit}) {
    commit(HIDE_EDIT_MENUS, false)
  },
  setSidebarUnfold ({commit}, type) {
    commit(SIDEBAR_UNFOLD, type)
  }
}

const getters = {
  getMenus (state) {
    return state.menus
  },
  getEditMenus (state) {
    return state.editMenus
  },
  getSidebarUnfoldInfo (state) {
    return state.sidebarUnfold
  }
}

const mutations = {
  [GET_MEUMS] (state, menus) {
    state.menus = menus
  },
  [SHOW_EDIT_MENUS] (state, status) {
    state.editMenus = status
  },
  [HIDE_EDIT_MENUS] (state, status) {
    state.editMenus = status
  },
  [SIDEBAR_UNFOLD] (state, type) {
    state.sidebarUnfold = type
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}
