import { jsx as _jsx } from "react/jsx-runtime";
import { Code, File, FileCode, FileLetterP, FileText, FileZipper, Headphones, MusicNote, Video, } from '@gravity-ui/icons';
import { Icon } from '@gravity-ui/uikit';
import { block } from "../../../utils/cn.js";
import "./FileIcon.css";
const b = block('file-icon');
const ICON_SIZE_MAP = { s: 12, m: 16, l: 20 };
const CODE_SUBTYPES = ['json', 'xml', 'html', 'javascript', 'typescript'];
const ARCHIVE_KEYWORDS = ['zip', 'tar', 'gzip'];
const TEXT_KEYWORDS = ['spreadsheet', 'csv', 'word', 'document'];
function getIconByMimeType(mimeType) {
    var _a;
    const type = mimeType.split('/')[0];
    const subtype = (_a = mimeType.split('/')[1]) !== null && _a !== void 0 ? _a : '';
    if (type === 'image')
        return File;
    if (type === 'audio' || subtype.includes('audio'))
        return Headphones;
    if (type === 'video')
        return Video;
    if (type === 'text')
        return subtype === 'plain' ? FileText : FileCode;
    if (subtype === 'pdf')
        return FileLetterP;
    if (CODE_SUBTYPES.includes(subtype))
        return FileCode;
    if (ARCHIVE_KEYWORDS.some((kw) => subtype.includes(kw)))
        return FileZipper;
    if (TEXT_KEYWORDS.some((kw) => subtype.includes(kw)))
        return FileText;
    if (subtype.includes('presentation'))
        return File;
    return File;
}
function getIconByExtension(ext) {
    const lower = ext.toLowerCase();
    if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'ico'].includes(lower))
        return File;
    if (['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a'].includes(lower))
        return MusicNote;
    if (['mp4', 'avi', 'mov', 'mkv', 'webm', 'flv'].includes(lower))
        return Video;
    if (['pdf'].includes(lower))
        return FileLetterP;
    if (['zip', 'tar', 'gz', 'rar', '7z', 'bz2'].includes(lower))
        return FileZipper;
    if (['js', 'ts', 'tsx', 'jsx', 'py', 'go', 'rs', 'java', 'cpp', 'c', 'cs'].includes(lower)) {
        return Code;
    }
    if (['json', 'xml', 'html', 'css', 'yml', 'yaml'].includes(lower))
        return FileCode;
    if (['txt', 'md', 'log', 'csv', 'tsv'].includes(lower))
        return FileText;
    return File;
}
function resolveIcon(mimeType, fileName) {
    if (mimeType)
        return getIconByMimeType(mimeType);
    if (fileName) {
        const parts = fileName.split('.');
        if (parts.length > 1)
            return getIconByExtension(parts[parts.length - 1]);
    }
    return File;
}
/**
 * FileIcon displays an icon representing a file based on its MIME type or file name extension.
 */
export const FileIcon = ({ mimeType, fileName, size = 'm', className }) => {
    const icon = resolveIcon(mimeType, fileName);
    return _jsx(Icon, { data: icon, size: ICON_SIZE_MAP[size], className: b({ size }, className) });
};
//# sourceMappingURL=FileIcon.js.map
