/**
 * Interpolate {key} and {{key}} placeholders in an i18n template string.
 * Only use for strings that come from t()/useT() — do not apply to arbitrary strings.
 *
 * interpolate('Hello {name}!', { name: 'Alex' }) -> 'Hello Alex!'
 * interpolate('You saved {{amount}}', { amount: '₪50' }) -> 'You saved ₪50'
 */
export function interpolate(
  template: string,
  vars: Record<string, string | number>,
): string {
  return template.replace(/\{\{(\w+)\}\}|\{(\w+)\}/g, (_, g1, g2) => {
    const key = g1 ?? g2;
    return key in vars ? String(vars[key]) : _;
  });
}