export default GlobalConfig = window.GlobalConfig;

export function addThousandSeparators(value, fractionDigits = 2) {
    if (!value) return null; // Handle empty or null values

    // Remove any non-numeric characters except commas and dots
    value = value.replace(/[^0-9,.]/g, "");

    // If the value contains multiple dots, assume dots are thousand separators
    if ((value.match(/\./g) || []).length > 1) {
        value = value.replace(/\./g, "");
    }

    // Convert to a proper decimal number
    let number = parseFloat(value.replace(",", "."));

    if (isNaN(number)) return null; // Return null if conversion fails

    // Format the number with thousand separators
    return new Intl.NumberFormat("en-US", {
        minimumFractionDigits: fractionDigits,
        maximumFractionDigits: fractionDigits,
    }).format(number);
}
