"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatRelativeTime = exports.formatCurrency = exports.formatPercentage = exports.formatDuration = exports.formatBytes = exports.formatNumber = void 0;
/**
 * Format a number with appropriate units and precision
 */
const formatNumber = (value, precision = 2) => {
    if (value === undefined || value === null)
        return 'N/A';
    const absValue = Math.abs(value);
    if (absValue >= 1e9) {
        return `${(value / 1e9).toFixed(precision)}B`;
    }
    else if (absValue >= 1e6) {
        return `${(value / 1e6).toFixed(precision)}M`;
    }
    else if (absValue >= 1e3) {
        return `${(value / 1e3).toFixed(precision)}K`;
    }
    return value.toFixed(precision);
};
exports.formatNumber = formatNumber;
/**
 * Format bytes into human-readable sizes
 */
const formatBytes = (bytes, precision = 2) => {
    if (bytes === 0)
        return '0 B';
    const k = 1024;
    const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return `${(bytes / Math.pow(k, i)).toFixed(precision)} ${sizes[i]}`;
};
exports.formatBytes = formatBytes;
/**
 * Format a duration in milliseconds to a human-readable string
 */
const formatDuration = (ms) => {
    if (ms < 1000) {
        return `${ms}ms`;
    }
    const seconds = ms / 1000;
    if (seconds < 60) {
        return `${seconds.toFixed(1)}s`;
    }
    const minutes = seconds / 60;
    if (minutes < 60) {
        return `${minutes.toFixed(1)}m`;
    }
    const hours = minutes / 60;
    if (hours < 24) {
        return `${hours.toFixed(1)}h`;
    }
    const days = hours / 24;
    return `${days.toFixed(1)}d`;
};
exports.formatDuration = formatDuration;
/**
 * Format a percentage value
 */
const formatPercentage = (value, precision = 1) => {
    return `${value.toFixed(precision)}%`;
};
exports.formatPercentage = formatPercentage;
/**
 * Format a currency value
 */
const formatCurrency = (value, currency = 'USD', precision = 2) => {
    return new Intl.NumberFormat('en-US', {
        style: 'currency',
        currency,
        minimumFractionDigits: precision,
        maximumFractionDigits: precision,
    }).format(value);
};
exports.formatCurrency = formatCurrency;
/**
 * Format a date relative to now (e.g., "2 hours ago")
 */
const formatRelativeTime = (date) => {
    const now = new Date();
    const then = typeof date === 'string' ? new Date(date) : date;
    const diffMs = now.getTime() - then.getTime();
    const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
    const seconds = Math.floor(diffMs / 1000);
    const minutes = Math.floor(seconds / 60);
    const hours = Math.floor(minutes / 60);
    const days = Math.floor(hours / 24);
    const months = Math.floor(days / 30);
    const years = Math.floor(months / 12);
    if (years > 0)
        return rtf.format(-years, 'year');
    if (months > 0)
        return rtf.format(-months, 'month');
    if (days > 0)
        return rtf.format(-days, 'day');
    if (hours > 0)
        return rtf.format(-hours, 'hour');
    if (minutes > 0)
        return rtf.format(-minutes, 'minute');
    return rtf.format(-seconds, 'second');
};
exports.formatRelativeTime = formatRelativeTime;
//# sourceMappingURL=formatters.js.map