const RGB_HEX = /^#?(?:([\da-f]{3})[\da-f]?|([\da-f]{6})(?:[\da-f]{2})?)$/i;
/** Ensure the consistency of colors between old and new colors */
const variantMapping = {
    healthy: 'statusHealthy',
    success: 'statusHealthy',
    warning: 'statusWarning',
    danger: 'statusCritical',
    selected: 'selectedActive',
    base: 'infoPrimary',
};
/** Translates the old colors into new colors while keeping the same name.
 * New names are also supported. */
export const getThemePropSelector = (key) => (props) => {
    var _a;
    const key_ = (_a = variantMapping[key]) !== null && _a !== void 0 ? _a : key;
    return props.theme[key_];
};
/** Translates the old colors into new colors while keeping same name.
 * New names are also supported. */
export const getThemeVariantSelector = () => (props) => {
    var _a;
    const theme = props.theme;
    const key = (_a = variantMapping[props.variant]) !== null && _a !== void 0 ? _a : props.variant;
    return theme[key];
};
/** Returns the theme color key for a given variant (e.g. for use with Icon color prop). */
export const getVariantThemeKey = (variant) => { var _a; return (_a = variantMapping[variant]) !== null && _a !== void 0 ? _a : variant; };
export const hex2RGB = (str) => {
    const [, short, long] = String(str).match(RGB_HEX) || [];
    if (long) {
        const value = Number.parseInt(long, 16);
        return [value >> 16, (value >> 8) & 0xff, value & 0xff];
    }
    else if (short) {
        const [r, g, b] = Array.from(short, (s) => Number.parseInt(s, 16)).map((n) => (n << 4) | n);
        return [r, g, b];
    }
    throw new Error('Invalid hex string provided');
};
export const convertRemToPixels = (rem) => {
    if (document.documentElement &&
        rem &&
        Number.isFinite(rem) &&
        !Number.isNaN(rem)) {
        return (rem * parseFloat(getComputedStyle(document.documentElement).fontSize) || 0);
    }
    return 0;
};
/**
 * Formats a number to ISO 80000-1 format:
 * - Space as thousands separator
 * - Dot as decimal separator
 * - Optional compact notation (10K, 1M, etc.)
 * - Very small values (< 0.001): scientific notation
 */
export const formatISONumber = (value, options = {}) => {
    const { decimals = 2, compact = false, fixedDecimals = false } = options;
    if (value === 0)
        return '0';
    const absValue = Math.abs(value);
    if (absValue < 0.001) {
        return value.toExponential();
    }
    // ISO format: space as thousands separator, dot as decimal separator
    // With optional compact notation (10K, 1M, etc.)
    return new Intl.NumberFormat('fr-FR', {
        minimumFractionDigits: fixedDecimals ? decimals : undefined,
        maximumFractionDigits: decimals,
        notation: compact ? 'compact' : 'standard',
    })
        .format(value)
        .replace(',', '.');
};
