import React, { useEffect, useState, createContext } from 'react';
import CheckRecord from '@/webPublic/FormInsertDiy/ExportComponent/CheckRecord'; // 查询类
import Apply from '@/webPublic/FormInsertDiy/AffairPage/ApplyPage'; // 申请
import BatchAudit from '@/webPublic/FormInsertDiy/AffairPage/AuditPage/BatchAudit'; // 批量审批
import Audit from '@/webPublic/FormInsertDiy/AffairPage/AuditPage/index.js'; // 审批
import Detail from '@/webPublic/FormInsertDiy/AffairPage/Detail'; //详情
import { Modal, message, notification, Popconfirm } from 'antd';
import { connect } from 'dva';

export const CreateC = createContext({
  routerConfig: {},
});


window.iframeParentComponent = {
  Modal,
  message,
  notification,
  Popconfirm,
};

function ActiveMenuComponent({
                               routerConfig,
                               ...otherProps
                             }) {
  const {
    component = '',
    appId
  } = routerConfig;
  const { location } = otherProps;
  const record = location?.state?.record;
  const [show, setShow] = useState(false);
  useEffect(
    () => {
      if (appId || record.id) {
        setShow(false);
        setTimeout(() => {
          setShow(true);
        }, 100);
      }
    },
    [appId, record],
  );
  if (!show) {
    return null;
  }

  let Res = <div>暂无此功能</div>;

  switch (component) {
    case 'CheckRecord': // 查询类应用
      Res = <CheckRecord workId={appId}/>;
      break;
    case 'Apply': // 申请类
      Res = <Apply workId={appId} {...otherProps} />;
      break;
    case 'Audit': // 审批类
      Res =  <Audit workId={appId} {...otherProps} />;
      break;
    case 'BatchAudit': // 批量审批
      Res =  <BatchAudit workId={appId}
                         {...otherProps}
      />;
      break;
    case 'Detail': // 详情
      Res = <Detail {...otherProps} />;
      break;
    default:
      break;
  }
  return (
    <CreateC.Provider value={{
      routerConfig,
    }}>
        {Res}
    </CreateC.Provider>
  );
}

export default connect(({}) => {
  return {};
})(ActiveMenuComponent);
