import { Upload, Button } from "antd";
import { UploadOutlined } from "@ant-design/icons";
import { parseUploadFileList, resolveUploadFileId } from "~/utils/mockUpload";

export default function FilingUpload({
  value,
  onChange,
  disabled,
  maxCount = 1,
  accept,
}) {
  const fileList = Array.isArray(value) ? value : parseUploadFileList(value);

  return (
    <Upload
      maxCount={maxCount}
      accept={accept}
      disabled={disabled}
      fileList={fileList}
      beforeUpload={() => false}
      onChange={(info) => {
        if (disabled) return;
        onChange?.(info.fileList);
      }}
    >
      {(!fileList || fileList.length < maxCount) && (
        <Button icon={<UploadOutlined />}>上传</Button>
      )}
    </Upload>
  );
}

export function resolveFilingUploadUrl(files) {
  return resolveUploadFileId(files);
}
