import { getUid } from '../../lib/uidUtils.js';
import { FileUploaderFileValidationResult } from './FileUploaderFileValidationResult.js';
export var FileUploaderFileStatus;
(function (FileUploaderFileStatus) {
    FileUploaderFileStatus["Attached"] = "Attached";
    FileUploaderFileStatus["Loading"] = "Loading";
    FileUploaderFileStatus["Uploaded"] = "Uploaded";
    FileUploaderFileStatus["Error"] = "Error";
    FileUploaderFileStatus["Warning"] = "Warning";
})(FileUploaderFileStatus || (FileUploaderFileStatus = {}));
export var getAttachedFile = function (file) {
    return {
        id: getUid(),
        originalFile: file,
        status: FileUploaderFileStatus.Attached,
        validationResult: FileUploaderFileValidationResult.ok(),
    };
};
export var codeFileExtensions = ['xml', 'html', 'json'];
export var pictureFileExtensions = ['jpg', 'png'];
export var presentationFileExtensions = ['pptx', 'ppt', 'odp'];
export var tableFileExtensions = ['xls', 'xlsx', 'ods'];
export var textFileExtensions = ['txt', 'docx', 'doc', 'rtf', 'odt'];
export var 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';
    }
}
export 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 });
}
export 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);
}
//# sourceMappingURL=fileUtils.js.map