export const wait = timeToDelay => new Promise(resolve => setTimeout(resolve, timeToDelay));

export const isEmpty = (value) => {
    if (value == "" || value == null || value == undefined || (value != null && typeof value == "object" && !Object.keys(value).length))
        return true;
    return false;
}

export const isPC = () => {
    const varUA = navigator.userAgent.toLowerCase();
    const isMobile = /iphone|ipad|ipod|android|blackberry|iemobile|opera mini/i.test(varUA);
    return !isMobile;
}

export const returnMimeTypes = (extension) => {
    const mimeTypes = {
        // Archive
        '7z': 'application/x-7z-compressed',
        'gz': 'application/gzip',
        'tar': 'application/x-tar',
        'zip': 'application/zip',

        // Audio
        'aac': 'audio/aac',
        'mp3': 'audio/mpeg',
        'ogg': 'audio/ogg',
        'opus': 'audio/opus',
        'wav': 'audio/wav',
        'webm': 'audio/webm',

        // Image
        'bmp': 'image/bmp',
        'gif': 'image/gif',
        'ico': 'image/x-icon',
        'jpeg': 'image/jpeg',
        'jpg': 'image/jpeg',
        'png': 'image/png',
        'svg': 'image/svg+xml',
        'tiff': 'image/tiff',
        'webp': 'image/webp',

        // Video
        'avi': 'video/x-msvideo',
        'mp4': 'video/mp4',
        'mpeg': 'video/mpeg',
        'ogg': 'video/ogg',
        'webm': 'video/webm',
        'mov': 'video/quicktime',
        'wmv': 'video/x-ms-wmv',

        // Document
        'doc': 'application/msword',
        'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'epub': 'application/epub+zip',
        'html': 'text/html',
        'htm': 'text/html',
        'odt': 'application/vnd.oasis.opendocument.text',
        'pdf': 'application/pdf',
        'ppt': 'application/vnd.ms-powerpoint',
        'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        'rtf': 'application/rtf',
        'txt': 'text/plain',
        'xls': 'application/vnd.ms-excel',
        'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'xml': 'application/xml',
        'json': 'application/json',
        'csv': 'text/csv',

        // Code / Script
        'css': 'text/css',
        'js': 'text/javascript',
        'json': 'application/json',
        'php': 'application/x-httpd-php',
        'xml': 'application/xml',

        // Font
        'woff': 'font/woff',
        'woff2': 'font/woff2',
        'ttf': 'font/ttf',
        'otf': 'font/otf',

        // Web
        'jsonld': 'application/ld+json',
        'webmanifest': 'application/manifest+json',

        // Others
        'bin': 'application/octet-stream',
        'exe': 'application/octet-stream',
        'apk': 'application/vnd.android.package-archive',
        'dll': 'application/x-msdownload',
        'iso': 'application/x-iso9660-image',
        'msi': 'application/x-msi',
        'torrent': 'application/x-bittorrent',

        // Unknown
        'default': 'application/octet-stream'
    }

    const ext = extension.trim().toLowerCase();
    return mimeTypes[ext] || mimeTypes['default'];
};
