/*
  Dictionary accessor. Components read the fully-typed dictionary object directly
  (`d.nav.projects`), which keeps compile-time key safety (I18N_SPEC §2). Runtime
  string paths are deliberately avoided — they'd lose that guarantee.
*/

import type { Dictionary } from './dictionary';
import { en } from './dictionary.en';
import { no } from './dictionary.no';
import type { Locale } from './locales';

const DICTS: Record<Locale, Dictionary> = { en, no };

/** Typed dictionary for a locale. */
export function useDict(locale: Locale): Dictionary {
  return DICTS[locale];
}

/** Replace {token} placeholders. The only interpolation mechanism (no plural engine). */
export function interpolate(
  template: string,
  params: Record<string, string | number> = {},
): string {
  return template.replace(/\{(\w+)\}/g, (match, key: string) =>
    key in params ? String(params[key]) : match,
  );
}

export type { Dictionary };
