function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
// 文件类型分类
export var FileCategory = /*#__PURE__*/ function(FileCategory) {
    FileCategory["Text"] = "text";
    FileCategory["Code"] = "code";
    FileCategory["Image"] = "image";
    FileCategory["Video"] = "video";
    FileCategory["Audio"] = "audio";
    FileCategory["PDF"] = "pdf";
    FileCategory["Word"] = "word";
    FileCategory["Excel"] = "excel";
    FileCategory["Presentation"] = "presentation";
    FileCategory["Archive"] = "archive";
    FileCategory["Other"] = "other";
    return FileCategory;
}({});
// 文件类型注册表
export var FILE_TYPES = {
    plainText: {
        category: "text",
        extensions: [
            'txt'
        ],
        mimeTypes: [
            'text/plain'
        ],
        nameKey: 'fileType.plainText'
    },
    markdown: {
        category: "text",
        extensions: [
            'md',
            'markdown'
        ],
        mimeTypes: [
            'text/markdown'
        ],
        nameKey: 'markdown'
    },
    image: {
        category: "image",
        extensions: [
            'jpg',
            'jpeg',
            'png',
            'gif',
            'bmp',
            'webp',
            'svg'
        ],
        mimeTypes: [
            'image/jpeg',
            'image/png',
            'image/gif',
            'image/bmp',
            'image/webp',
            'image/svg+xml'
        ],
        nameKey: 'fileType.image'
    },
    video: {
        category: "video",
        extensions: [
            'mp4',
            'webm',
            'ogv',
            'mov',
            'avi',
            'mkv',
            'flv',
            '3gp',
            'm4v'
        ],
        mimeTypes: [
            'video/mp4',
            'video/webm',
            'video/ogg',
            'video/quicktime',
            'video/x-msvideo',
            'video/x-matroska',
            'video/x-flv',
            'video/3gpp',
            'video/x-m4v'
        ],
        nameKey: 'fileType.video'
    },
    audio: {
        category: "audio",
        extensions: [
            'mp3',
            'wav',
            'ogg',
            'aac',
            'm4a',
            'flac',
            'wma',
            'opus'
        ],
        mimeTypes: [
            'audio/mpeg',
            'audio/wav',
            'audio/ogg',
            'audio/aac',
            'audio/mp4',
            'audio/flac',
            'audio/x-ms-wma',
            'audio/opus'
        ],
        nameKey: 'fileType.audio'
    },
    pdf: {
        category: "pdf",
        extensions: [
            'pdf'
        ],
        mimeTypes: [
            'application/pdf'
        ],
        nameKey: 'fileType.pdf'
    },
    word: {
        category: "word",
        extensions: [
            'doc',
            'docx'
        ],
        mimeTypes: [
            'application/msword',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        ],
        nameKey: 'fileType.word'
    },
    excel: {
        category: "excel",
        extensions: [
            'xls',
            'xlsx'
        ],
        mimeTypes: [
            'application/vnd.ms-excel',
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        ],
        nameKey: 'fileType.excel'
    },
    csv: {
        category: "excel",
        extensions: [
            'csv'
        ],
        mimeTypes: [
            'text/csv',
            'application/csv',
            'application/vnd.ms-excel'
        ],
        nameKey: 'fileType.csv'
    },
    powerpoint: {
        category: "presentation",
        extensions: [
            'ppt',
            'pptx'
        ],
        mimeTypes: [
            'application/vnd.ms-powerpoint',
            'application/vnd.openxmlformats-officedocument.presentationml.presentation'
        ],
        nameKey: 'fileType.powerpoint'
    },
    archive: {
        category: "archive",
        extensions: [
            'zip',
            'rar',
            '7z',
            'tar',
            'gz',
            'bz2'
        ],
        mimeTypes: [
            'application/zip',
            'application/x-rar-compressed',
            'application/x-7z-compressed',
            'application/x-tar',
            'application/gzip',
            'application/x-bzip2'
        ],
        nameKey: 'fileType.archive'
    },
    // 代码文件类型
    javascript: {
        category: "code",
        extensions: [
            'js',
            'mjs',
            'cjs'
        ],
        mimeTypes: [
            'text/javascript',
            'application/javascript'
        ],
        nameKey: 'javascript'
    },
    typescript: {
        category: "code",
        extensions: [
            'ts'
        ],
        mimeTypes: [
            'text/typescript',
            'application/typescript'
        ],
        nameKey: 'typescript'
    },
    react: {
        category: "code",
        extensions: [
            'jsx',
            'tsx'
        ],
        mimeTypes: [
            'text/jsx',
            'text/tsx'
        ],
        nameKey: 'react'
    },
    python: {
        category: "code",
        extensions: [
            'py',
            'pyw',
            'pyi'
        ],
        mimeTypes: [
            'text/x-python',
            'application/x-python-code'
        ],
        nameKey: 'python'
    },
    java: {
        category: "code",
        extensions: [
            'java'
        ],
        mimeTypes: [
            'text/x-java-source'
        ],
        nameKey: 'java'
    },
    cpp: {
        category: "code",
        extensions: [
            'cpp',
            'cc',
            'cxx',
            'c++',
            'hpp',
            'hxx',
            'h++'
        ],
        mimeTypes: [
            'text/x-c++src',
            'text/x-c++hdr'
        ],
        nameKey: 'c++'
    },
    c: {
        category: "code",
        extensions: [
            'c',
            'h'
        ],
        mimeTypes: [
            'text/x-csrc',
            'text/x-chdr'
        ],
        nameKey: 'c'
    },
    csharp: {
        category: "code",
        extensions: [
            'cs'
        ],
        mimeTypes: [
            'text/x-csharp'
        ],
        nameKey: 'c#'
    },
    go: {
        category: "code",
        extensions: [
            'go'
        ],
        mimeTypes: [
            'text/x-go'
        ],
        nameKey: 'go'
    },
    rust: {
        category: "code",
        extensions: [
            'rs'
        ],
        mimeTypes: [
            'text/x-rust'
        ],
        nameKey: 'rust'
    },
    php: {
        category: "code",
        extensions: [
            'php',
            'php3',
            'php4',
            'php5',
            'phtml'
        ],
        mimeTypes: [
            'text/x-php',
            'application/x-httpd-php'
        ],
        nameKey: 'php'
    },
    ruby: {
        category: "code",
        extensions: [
            'rb',
            'rbw'
        ],
        mimeTypes: [
            'text/x-ruby'
        ],
        nameKey: 'ruby'
    },
    shell: {
        category: "code",
        extensions: [
            'sh',
            'bash',
            'zsh',
            'fish'
        ],
        mimeTypes: [
            'text/x-shellscript',
            'application/x-sh'
        ],
        nameKey: 'fileType.shell'
    },
    powershell: {
        category: "code",
        extensions: [
            'ps1',
            'psm1',
            'psd1'
        ],
        mimeTypes: [
            'text/x-powershell'
        ],
        nameKey: 'powershell'
    },
    sql: {
        category: "code",
        extensions: [
            'sql'
        ],
        mimeTypes: [
            'text/x-sql',
            'application/sql'
        ],
        nameKey: 'sql'
    },
    lua: {
        category: "code",
        extensions: [
            'lua'
        ],
        mimeTypes: [
            'text/x-lua'
        ],
        nameKey: 'lua'
    },
    perl: {
        category: "code",
        extensions: [
            'pl',
            'pm',
            'perl'
        ],
        mimeTypes: [
            'text/x-perl'
        ],
        nameKey: 'perl'
    },
    scala: {
        category: "code",
        extensions: [
            'scala',
            'sc'
        ],
        mimeTypes: [
            'text/x-scala'
        ],
        nameKey: 'scala'
    },
    config: {
        category: "code",
        extensions: [
            'json',
            'yaml',
            'yml',
            'toml',
            'ini',
            'conf',
            'cfg',
            'properties'
        ],
        mimeTypes: [
            'application/json',
            'application/yaml',
            'text/yaml',
            'application/toml',
            'text/plain',
            'application/x-wine-extension-ini'
        ],
        nameKey: 'fileType.config'
    }
};
// 工具函数
export var getFileType = function getFileType(filename) {
    var _filename_split_pop;
    var extension = ((_filename_split_pop = filename.split('.').pop()) === null || _filename_split_pop === void 0 ? void 0 : _filename_split_pop.toLowerCase()) || '';
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    try {
        for(var _iterator = Object.entries(FILE_TYPES)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var _step_value = _sliced_to_array(_step.value, 2), type = _step_value[0], definition = _step_value[1];
            if (definition.extensions.includes(extension)) {
                return type;
            }
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
    return 'plainText';
};
export var getMimeType = function getMimeType(fileType) {
    return FILE_TYPES[fileType].mimeTypes[0];
};
export var getFileCategory = function getFileCategory(fileType) {
    var _FILE_TYPES_fileType;
    return FILE_TYPES === null || FILE_TYPES === void 0 ? void 0 : (_FILE_TYPES_fileType = FILE_TYPES[fileType]) === null || _FILE_TYPES_fileType === void 0 ? void 0 : _FILE_TYPES_fileType.category;
};
/**
 * Get the localized display name for a file type.
 * Falls back to the nameKey itself when no locale is provided.
 */ export var getFileTypeName = function getFileTypeName(fileType, locale) {
    var _ref;
    var definition = FILE_TYPES[fileType];
    if (!definition) return fileType;
    return (_ref = locale === null || locale === void 0 ? void 0 : locale[definition.nameKey]) !== null && _ref !== void 0 ? _ref : definition.nameKey;
};
