"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.transferRcFileToUploadFile = exports.isImg = exports.getFileTypeMapIcon = exports.getFileSize = void 0;

var _doc = _interopRequireDefault(require("./img/doc.svg"));

var _other = _interopRequireDefault(require("./img/other.svg"));

var _pdf = _interopRequireDefault(require("./img/pdf.svg"));

var _ppt = _interopRequireDefault(require("./img/ppt.svg"));

var _radio = _interopRequireDefault(require("./img/radio.svg"));

var _video = _interopRequireDefault(require("./img/video.svg"));

var _xls = _interopRequireDefault(require("./img/xls.svg"));

var _folder = _interopRequireDefault(require("./img/folder.svg"));

var _form = _interopRequireDefault(require("./img/form.svg"));

var _mind = _interopRequireDefault(require("./img/mind.svg"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var getFileSize = function getFileSize(fileSize) {
  if (!fileSize) return '';

  if (fileSize < 1024) {
    return "".concat(fileSize, "KB");
  }

  if (fileSize < 1024 * 1024) {
    var _temp = fileSize / 1024;

    _temp = Number(_temp.toFixed(2));
    return "".concat(_temp, "M");
  }

  var temp = fileSize / (1024 * 1024);
  temp = Number(temp.toFixed(2));
  return "".concat(temp, "GB");
};

exports.getFileSize = getFileSize;

var getFileTypeMapIcon = function getFileTypeMapIcon(fileType) {
  // if (/^(jpg|png|gif|jpeg|image|JPG|PNG|GIF|JPEG)$/.test(fileType)) {
  //   return
  // } else
  if (/^(mp3|ogg|ape|flac)$/.test(fileType.toLowerCase())) {
    return _radio["default"];
  }

  if (/^(avi|wmv|mov|mp4|rmvb)$/.test(fileType.toLowerCase())) {
    return _video["default"];
  }

  if (/^(pptx|ppt|slide)$/.test(fileType.toLowerCase())) {
    return _ppt["default"];
  }

  if (/^(doc|docx)$/.test(fileType.toLowerCase())) {
    return _doc["default"];
  }

  if (/^(xls|xlsx|sheet)$/.test(fileType.toLowerCase())) {
    return _xls["default"];
  }

  if (/^(pdf)$/.test(fileType.toLowerCase())) {
    return _pdf["default"];
  }

  if (/^(folder)$/.test(fileType.toLowerCase())) {
    return _folder["default"];
  }

  if (/^(form)$/.test(fileType.toLowerCase())) {
    return _form["default"];
  }

  if (/^(mind)$/.test(fileType.toLowerCase())) {
    return _mind["default"];
  }

  return _other["default"];
};

exports.getFileTypeMapIcon = getFileTypeMapIcon;

var isImg = function isImg(fileType) {
  if (/^(jpg|png|gif|jpeg|image|JPG|PNG|GIF|JPEG)$/.test(fileType)) {
    return true;
  }

  return false;
}; // export const getPreviewImgs = (files: UploadResultObj[]) => files.filter((file) => isImg(file.FileType)).map((file) => ({
//   documentId: file.documentId,
//   bigImageUrl: file.ClientUrl,
//   fileName: file.FileName,
//   fileType: file.FileType,
//   previewUrl: file.ClientUrl,
//   deleteable: file.Deleteable,
//   smallImageUrl: file.ClientUrl,
//   createDate: "",
//   documentSource: "",
//   downloadUrl: file.DownloadUrl,
//   imageUrl: file.ClientUrl,
//   relatedFileId: null,
//   size: file.FileSize,
//   thumbnailGenerated: null,
// }));

/**
 * uid: "rc-upload-1647410201539-4"
  lastModified: 1624862495244
  lastModifiedDate: Mon Jun 28 2021 14:41:35 GMT+0800 (中国标准时间) {}
  name: "【去哪儿网】2021-06-25 北京-青岛机票订单电子报销凭证.pdf"
  size: 36988
  type: "application/pdf"
  webkitRelativePath: ""
 */


exports.isImg = isImg;

var transferRcFileToUploadFile = function transferRcFileToUploadFile(file) {
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  return _objectSpread({
    FileName: file.name,
    Id: file.uid,
    Size: Math.round(file.size * 10 / 1024) / 10,
    MediaType: file.type,
    Deleteable: true
  }, extra);
};

exports.transferRcFileToUploadFile = transferRcFileToUploadFile;