"use strict";exports.__esModule = true;exports.codeFileExtensions = exports.archiveFileExtensions = exports.FileUploaderFileStatus = void 0;exports.createFile = createFile;exports.getAttachedFile = void 0;exports.getFileUploaderTypeIcon = getFileUploaderTypeIcon;exports.textFileExtensions = exports.tableFileExtensions = exports.presentationFileExtensions = exports.pictureFileExtensions = void 0;var _uidUtils = require("../../lib/uidUtils");

var _FileUploaderFileValidationResult = require("./FileUploaderFileValidationResult");var







FileUploaderFileStatus = exports.FileUploaderFileStatus = /*#__PURE__*/function (FileUploaderFileStatus) {FileUploaderFileStatus["Attached"] = "Attached";FileUploaderFileStatus["Loading"] = "Loading";FileUploaderFileStatus["Uploaded"] = "Uploaded";FileUploaderFileStatus["Error"] = "Error";FileUploaderFileStatus["Warning"] = "Warning";return FileUploaderFileStatus;}({});



























var getAttachedFile = exports.getAttachedFile = function getAttachedFile(file) {
  return {
    id: (0, _uidUtils.getUid)(),
    originalFile: file,
    status: FileUploaderFileStatus.Attached,
    validationResult: _FileUploaderFileValidationResult.FileUploaderFileValidationResult.ok()
  };
};

var codeFileExtensions = exports.codeFileExtensions = ['xml', 'html', 'json'];
var pictureFileExtensions = exports.pictureFileExtensions = ['jpg', 'png'];
var presentationFileExtensions = exports.presentationFileExtensions = ['pptx', 'ppt', 'odp'];
var tableFileExtensions = exports.tableFileExtensions = ['xls', 'xlsx', 'ods'];
var textFileExtensions = exports.textFileExtensions = ['txt', 'docx', 'doc', 'rtf', 'odt'];
var archiveFileExtensions = exports.archiveFileExtensions = ['zip', 'rar', '7zip', '7z'];

function getFileExtension(file) {
  var name = file.name;
  var match = /\.([^.]+)$/.exec(name);

  return match ? match[1] : '';
}

function getFileType(file) {
  var extension = getFileExtension(file);

  if (extension === '' && file.type === '') {
    return 'folder';
  }

  switch (true) {
    case extension === 'pdf':
      return 'pdf';
    case codeFileExtensions.includes(extension):
      return 'code';
    case pictureFileExtensions.includes(extension):
      return 'picture';
    case presentationFileExtensions.includes(extension):
      return 'presentation';
    case tableFileExtensions.includes(extension):
      return 'table';
    case textFileExtensions.includes(extension):
      return 'text';
    case archiveFileExtensions.includes(extension):
      return 'archive';

    default:
      return 'unknown';
  }
}

function createFile(filename, content, type) {if (content === void 0) {content = 'content';}if (type === void 0) {type = 'text/plain';}
  return new File([content], filename, { type: type });
}

function getFileUploaderTypeIcon(file, error, warning) {if (error === void 0) {error = false;}if (warning === void 0) {warning = false;}
  if (error) {
    return 'error';
  }

  if (warning) {
    return 'warning';
  }

  return getFileType(file);
}