/**
 * Get file type category based on MIME type
 * @param {string} mime - The MIME type of the file
 * @returns {string} The file type category
 */
export function getFileTypeByMime(mime) {
    if (!mime) return 'unknown';

    const mimeType = mime.toLowerCase();

    // Video files
    if (mimeType.startsWith('video/')) {
        return 'video';
    }

    // Audio files
    if (mimeType.startsWith('audio/')) {
        return 'audio';
    }

    // Image files
    if (mimeType.startsWith('image/')) {
        return 'image';
    }

    // PDF files
    if (mimeType === 'application/pdf') {
        return 'pdf';
    }

    // Document files
    if ([
        'application/msword',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'application/vnd.ms-excel',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/vnd.ms-powerpoint',
        'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        'application/rtf',
        'text/plain',
        'text/csv'
    ].includes(mimeType)) {
        return 'document';
    }

    // Compressed files
    if ([
        'application/zip',
        'application/x-rar-compressed',
        'application/x-7z-compressed',
        'application/x-tar',
        'application/gzip'
    ].includes(mimeType)) {
        return 'compressed';
    }

    return 'other';
}

/**
 * Get Chinese file type category based on MIME type
 * @param {string} mime - The MIME type of the file
 * @returns {string} The Chinese file type category
 */
export function getFileTypeByMimeCN(mime) {
    console.log("mime:", mime)
    const typeMap = {
        'video': '视频',
        'audio': '音频',
        'image': '图片',
        'pdf': 'PDF文档',
        'document': '文档',
        'compressed': '压缩包',
        'other': '其他',
        'unknown': '未知'
    };

    return typeMap[getFileTypeByMime(mime)];
}

/**
 * Get file icon component based on file extension
 * @param {Object} file - The file object containing name property
 * @param {Object} icons - The icons object containing icon components
 * @returns {Component} The icon component
 */
export function getFileIcon(file, icons) {
    if (!file?.name) return icons.BsFileEarmark;

    const ext = file.name.split('.').pop()?.toLowerCase();

    // Images
    if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'].includes(ext)) {
        return icons.BsFileImage;
    }

    // Videos
    if (['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv'].includes(ext)) {
        return icons.BsFilePlayFill;
    }

    // Audio
    if (['mp3', 'wav', 'ogg', 'aac', 'm4a'].includes(ext)) {
        return icons.BsFileMusic;
    }

    // Documents
    if (['doc', 'docx'].includes(ext)) {
        return icons.BsFileWord;
    }
    if (['xls', 'xlsx'].includes(ext)) {
        return icons.BsFileExcel;
    }
    if (['ppt', 'pptx'].includes(ext)) {
        return icons.BsFilePpt;
    }
    if (ext === 'pdf') {
        return icons.BsFilePdf;
    }
    if (['txt', 'rtf'].includes(ext)) {
        return icons.BsFileText;
    }

    // Archives
    if (['zip', 'rar', '7z', 'tar', 'gz'].includes(ext)) {
        return icons.BsFileZip;
    }

    return icons.BsFileEarmark;
}

