/**
 * Normalizes a locale-formatted number string to a format
 * that `Number.parseFloat` can handle.
 *
 * @param value - The locale-formatted number string
 * @param locale - A locale string (e.g. 'sv', 'sv-SE', 'en_us'). The primary
 *   language subtag is extracted and used for matching.
 * @returns A normalized string with dot as decimal separator
 */
export function normalizeValue(value, locale) {
    const language = locale.toLowerCase().split(/[-_]/)[0];
    switch (language) {
        case 'da':
        case 'de':
        case 'nl': {
            return value.replaceAll('.', '').replace(',', '.');
        }
        case 'nb':
        case 'no':
        case 'sv':
        case 'fi':
        case 'fr': {
            return value.replaceAll(/[\s\u00A0]/g, '').replace(',', '.');
        }
        case 'en': {
            return value.replaceAll(',', '');
        }
        default: {
            return value;
        }
    }
}
