import { connect } from 'umi';
import MenuPanelComponent from '../../components/MenuPanel/MenuPanel';

function MenuPanel({ dispatch, menuPanel, app }) {
  const MenuPanelProps = {
    app,
    menuPanel,
    onGetMenuPanel: getMenuPanel, /* 一级菜单 */
    onAddPane: getAddPane, /* 增加标签 */
    onFormHeader: getFormHeader, /* 获取窗体配置 */
    onAddParameter: getAddParameter, /* 增加常用操作 */
    onDelParameter: getDelParameter, /* 删除常用操作 */
  };

  function getMenuPanel(url) {
    /* 获取菜单 */
    dispatch({ type: 'menuPanel/getMenuPanel', payload: { url } });
  }

  function getAddPane(pane) {
    /* 增加标签 */
    dispatch({ type: 'app/addPane', payload: { pane } });
  }

  function getFormHeader(url, sTabId, route) {
    /* 获取表内容配置 */
    dispatch({ type: 'mergeTable/getFormHeader', payload: { url, sTabId, route } });
  }

  function getAddParameter(value, url) {
    /* 增加常用操作 */
    dispatch({ type: 'app/getAddParameter', payload: { value, url } });
  }

  function getDelParameter(value, url) {
    /* 删除常用操作 */
    dispatch({ type: 'app/getDelParameter', payload: { value, url } });
  }

  return (
    <div>
      <MenuPanelComponent {...MenuPanelProps} />
    </div>
  );
}

export default connect(({ menuPanel, app }) => ({ menuPanel, app }))(MenuPanel);
