'use strict';

var fileMetadata = require('./file-metadata-rQ0WzFlZ.js');

/**
 *
 * @param file
 */
function createFileInfo(file) {
    const limeFile = {
        id: crypto.randomUUID(),
        filename: file.name,
        contentType: file.type,
        size: file.size,
        fileContent: file,
    };
    limeFile.icon = {
        name: fileMetadata.getFileIcon(limeFile),
        title: fileMetadata.getFileExtensionTitle(limeFile),
        color: fileMetadata.getFileColor(limeFile),
        backgroundColor: fileMetadata.getFileBackgroundColor(limeFile),
    };
    return limeFile;
}
/**
 *
 * @param file
 * @param accept
 */
function isTypeAccepted(file, accept) {
    if (accept === undefined || accept === '*') {
        return true;
    }
    const acceptList = accept.split(',').map((raw) => raw.trim());
    return acceptList.some((acceptedType) => {
        if (acceptedType === file.contentType) {
            return true;
        }
        if (acceptedType.endsWith('/*')) {
            const baseType = acceptedType.split('/')[0];
            return file.contentType.startsWith(`${baseType}/`);
        }
        if (acceptedType.startsWith('.')) {
            const fileType = acceptedType.split('.')[1];
            return file.contentType.endsWith(`/${fileType}`);
        }
    });
}

exports.createFileInfo = createFileInfo;
exports.isTypeAccepted = isTypeAccepted;
