import InitForm from '../InitForm';
import { Drawer } from 'antd';
import React, { useState, memo } from 'react';
import DetailPro from '../DetailPro';
import PropTypes from 'prop-types';

function DrawerPro(props) {
  let pushSettingFlag = props.pushSettingFlag;
  let newProps = { ...props };
  delete newProps.children;
  const detailprops = {
    ...newProps,
    detailpath: props.detailpath,
    fields: props.fields,
    detailData: props.detailData,
  };

  return (
    <Drawer
      maskClosable={false}
      placement="right"
      closable={true}
      getContainer={false}
      style={{ position: 'absolute', transform: 'translateX(0)', maxWidth: '100%' }}
      width={'100%'}
      destroyOnClose={true}
      {...props}
    >
      {props.val == 'only' && props.children}
      {props.val == 'only' ? null : props.val == 'detail' ? (
        <DetailPro {...detailprops} />
      ) : (
        <InitForm {...newProps} />
      )}
      {pushSettingFlag ? (
        <a
          id="pushSettingBtn"
          onClick={() => {
            props.checkVariableOpen();
          }}
        >
          查看变量
        </a>
      ) : null}
    </Drawer>
  );
}

DrawerPro.propTypes = {
  detailpath: PropTypes.string, //详情
  params: PropTypes.object, //详情｜表单编辑 参数
  fields: PropTypes.array, //详情列表
  detailData: PropTypes.object, //详情数据
};

export default DrawerPro;
