import React from 'react';
import { connect } from 'umi';
import ExamineMobileComponent from '../../../mobile/common/ExamineMobile';
import * as commonUtils from '../../../utils/utils';

function ExamineMobile({
  dispatch, app, content, sModelsId, location,
}) {
  /* 只有state与sModelsId同时为空时 返回空白页,设备是固定模块id */
  if (location.state === null && commonUtils.isEmptyObject(sModelsId)) {
    return (<div />);
  }
  function removePane(changePanes, currentPane) {
    dispatch({ type: 'app/removePane', payload: { changePanes, currentPane } });
  }
  let param = {};
  if (commonUtils.isNotEmptyObject(location.state) && location.state.sParam) {
    param = commonUtils.convertStrToObj(location.state.sParam);
  } else {
    param = commonUtils.convertStrToObj(location.state);
  }
  const ExamineMobileProps = {
    sModelsId,
    app,
    content,
    dispatch,
    ...param,
    onRemovePane: removePane,
  };

  return (
    <ExamineMobileComponent {...ExamineMobileProps} />
  );
}

export default connect(({ app, content }) =>
  ({ app, content }))(ExamineMobile);
