import React, { useState,useEffect} from 'react';

import { Upload,Button,  message,Row,Col } from 'antd';
import { UploadOutlined } from '@ant-design/icons';

// { imageType: "tosContract", extends: extend }
//"/tos/image/upload"

import { Fromate2 } from '@/utils/method'
const FileUpload = (props: any) => {
  
  const {value,onChange}=props
  const [fileList, setFileList] = useState([]);
  

  const uploadProps = {
    accept:".pdf,",
    action:props.url,
    data: props.data,
    fileList: fileList,
    showUploadList:false,
    onChange({ file, fileList }) {
      let tmp=fileList
      setFileList(tmp.filter(file => !!file.status))
      if (file.status == 'done') {
        console.log(fileList);

        message.success(file.name, 3)
        if (props.reg != null) {
          onChange(Fromate2(fileList,props.reg))
        } else {
          onChange(fileList)
        }
      }
    },
  };

  return (
    <>
      <Row gutter={8}>
      <Col><div style={{lineHeight:2}}>{props.title}</div></Col>
        <Col>
          <Upload {...uploadProps}>
            <Button>
              <UploadOutlined /> Upload
            </Button>
        </Upload>
        </Col>
      </Row>

    </>
  );
};

export default FileUpload;
