import { defaultLocale, useBalConfig } from "./config";
const getLocale = () => {
    const config = useBalConfig();
    // workaround for swiss french locale which uses non standard number formatting
    if (config && config.locale && config.locale === 'fr-CH') {
        return 'de-CH';
    }
    return (config && config.locale) || defaultLocale;
};
export function getDecimalSeparator() {
    return Intl.NumberFormat(getLocale())
        .format(1.1)
        .replace(/\p{Number}/gu, '');
}
export const getDecimalSeparators = () => {
    if (getThousandSeparator() !== '.') {
        return [getDecimalSeparator(), '.'];
    }
    return [getDecimalSeparator()];
};
export function getThousandSeparator() {
    return Intl.NumberFormat(getLocale())
        .format(11111)
        .replace(/\p{Number}/gu, '');
}
export function formatLocaleNumber(number, minimumFractionDigits) {
    const options = minimumFractionDigits !== undefined ? { minimumFractionDigits, maximumFractionDigits: minimumFractionDigits } : {};
    const formattedNumber = Intl.NumberFormat(getLocale(), Object.assign({}, options)).format(number);
    if (formattedNumber === 'NaN') {
        return '';
    }
    return formattedNumber;
}
export const parseLocaleNumber = (stringNumber) => {
    const thousandSeparator = getThousandSeparator();
    const decimalSeparator = getDecimalSeparator();
    return parseFloat(stringNumber
        .replace(new RegExp('\\' + thousandSeparator, 'g'), '')
        .replace(new RegExp('\\' + decimalSeparator), '.'));
};
export const getNegativeSymbol = () => {
    return '-';
};
export const parseFloatString = (value) => {
    return value.replace(getDecimalSeparator(), '.');
};
export const formatFloatString = (value) => {
    return value.replace('.', getDecimalSeparator());
};
