"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isImg = exports.getPreviewImgs = 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 }; }

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

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

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

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

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

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

  var temp = fileSize / (1024 * 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;
};

exports.isImg = isImg;

var getPreviewImgs = function getPreviewImgs(files) {
  return files.filter(function (file) {
    return isImg(file.FileType);
  }).map(function (file) {
    return {
      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
    };
  });
};

exports.getPreviewImgs = getPreviewImgs;