/**
 * Shared number-formatting helper used by `<Progress.Root>` and
 * `<Meter.Root>`. Both components format a numeric value for display using
 * the same algorithm: if an explicit `format` is provided, pass the value
 * through `Intl.NumberFormat` verbatim; otherwise use a percent formatter
 * applied to `value / 100`.
 *
 * A module-scope cache keyed by `(locale, options)` keeps repeated formats
 * O(1). Construction of `Intl.NumberFormat` is the expensive step; the
 * formatters themselves are cheap to re-use.
 */

const FORMATTER_CACHE = new Map();
function getFormatter(locale, options) {
  const key = JSON.stringify({
    locale,
    options
  });
  const cached = FORMATTER_CACHE.get(key);
  if (cached) return cached;
  const formatter = new Intl.NumberFormat(locale, options);
  FORMATTER_CACHE.set(key, formatter);
  return formatter;
}

/**
 * Formats a numeric value for display. Returns `""` if `value` is `null`
 * (matches progress's indeterminate state). If `format` is undefined, the
 * default is a percentage applied to `value / 100` — so a raw value of `42`
 * yields `"42%"` under an `en-US` locale.
 */
export function formatNumberValue(value, locale, format) {
  if (value == null) return "";
  if (!format) {
    return getFormatter(locale, {
      style: "percent"
    }).format(value / 100);
  }
  return getFormatter(locale, format).format(value);
}
//# sourceMappingURL=format-number.jsx.map
