/**
 * Format file size to human readable string
 * @param {number} bytes - The file size in bytes
 * @returns {string} Formatted file size with unit
 */
export function formatFileSize(bytes) {
    if (bytes === 0) return "0 B";
    const k = BigInt(1024);
    const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];

    // Convert input to BigInt
    const bytesValue = BigInt(bytes);

    // Calculate the appropriate unit
    let i = 0;
    let size = bytesValue;
    while (size >= k && i < sizes.length - 1) {
        size = size / k;
        i++;
    }

    // Convert back to number and format with commas
    return `${Number(size).toLocaleString("en-US")} ${sizes[i]}`;
}
