/**
 * Persian (Extended Arabic-Indic, U+06F0–U+06F9) zero, and Arabic-Indic (U+0660–U+0669)
 * zero. ASR output can carry either block, sometimes mixed with ASCII in one transcript.
 */
const PERSIAN_ZERO = 0x06f0;
const ARABIC_INDIC_ZERO = 0x0660;

/**
 * Normalise Persian and Arabic-Indic digits to ASCII. Non-digits pass through.
 *
 * Deliberately wider than the frontend original, which only handles the Persian block:
 * this parses model/ASR output rather than keystrokes, so both blocks must be accepted
 * or a spoken date or tooth number silently degrades to "unresolved".
 *
 * Lives on its own rather than inside jalali.ts because tooth codes need it too, and a
 * tooth module reaching into the calendar module would read as an accident.
 */
export function toLatinDigits(value: string): string {
  return value.replace(/[۰-۹٠-٩]/g, (ch) => {
    const code = ch.charCodeAt(0);
    const base = code >= PERSIAN_ZERO ? PERSIAN_ZERO : ARABIC_INDIC_ZERO;
    return String(code - base);
  });
}
