import React, { useState, useEffect } from 'react';
import { Modal, Space, Button } from 'antd';
import ParseForm from 'parseForm';

import { LayerSetting } from '@/services/gis/gis';
const PerviewPrase = props => {
  const { visible, onCancel, accountData } = props;
  const [loading, setLoading] = useState(false);
  const [data, setData] = useState({});

  useEffect(() => {
    console.log(accountData);
    if (visible) {
      let tablesSchema = {
        child: {},
        groups: accountData.flowNodeMeta.groups,
        values: [],
        modules: [],
        relationForm: {},
      };
      LayerSetting({ client: 'sandbox' }).then(res => {
        let dataArea = res.data.find(i => i.layerType == 'PipenetLayer');
        console.log(res.data[0]);
        let ss = {
          layers: [dataArea],
        };
        let depart = { OID: 1017, code: '1-1016-1017', name: '管理员' };
        let userInfo = { OID: 1, fullName: '总经理', loginName: 'admin', depart };
        window.globalConfig = {
          ...window.globalConfig,
          mapsettings: ss,
          userInfo,
        };
      });

      setData(tablesSchema);
    }
  }, [visible]);

  return (
    <Modal
      title="预览"
      bodyStyle={{
        width: '100%',
        minHeight: '200px',
        maxHeight: '780px',
        overflow: 'scroll',
        overflowX: 'hidden',
      }}
      width="1800px"
      style={{ marginTop: '-80px' }}
      destroyOnClose
      maskClosable={false}
      footer={
        <Space>
          <Button onClick={onCancel} type="primary">
            关闭
          </Button>
        </Space>
      }
      {...props}
      confirmLoading={loading}
      forceRender
      getContainer={false}
    >
      {console.log(data)}
      {visible && <ParseForm tablesSchema={data} noButtons />}
    </Modal>
  );
};
export default PerviewPrase;
