/* eslint-disable no-undef */
import * as menuPanelService from '../services/services';

export default {
  namespace: 'menuPanel',
  state: {
    panelMenus: [], /* 面板菜单 */
    dataId: {}, /* id详情 */
  },
  reducers: {
    setPanelMenus(state, { payload: { panelMenus } }) {
      return { ...state, panelMenus };
    },
  },
  effects: {
    *getMenuPanel({ payload }, { put, call, select }) {
      const { url } = payload;
      const token = yield select(state => state.app.token);
      const { data } = yield call(menuPanelService.getService, token, url);
      if (data.code === 1) {
        const panelMenus = data.dataset.rows;
        yield put({ type: 'setPanelMenus', payload: { panelMenus } });
      } else {
        yield put({ type: 'app/throwError', payload: data });
      }
    },
  },
  subscriptions: {},
};
