import { type TranslationNamespace } from './Resources'
import LibraryTranslationInstance from './LibraryTranslationInstance'
import { tr } from '../services/TranslationHelpers'

export type TranslationKey = `${TranslationNamespace}:${string}`

/**
 * Translation helper function
 * @param key - namespace:key of the translation (in the format 'namespace:key')
 * @param values - (optional) values to be interpolated into the translated string
 * @returns translated string
 **/
export const t = (
  namespaceAndKey: `${TranslationNamespace}:${string}`,
  values?: Record<string, unknown>,
) => tr(namespaceAndKey, LibraryTranslationInstance, values)

/**
 * Translation helper function, shorthand for using the "common" namespace `t('common:key')`
 * @param key - key of the translation
 * @param values - (optional) values to be interpolated into the translated string
 * @returns translated string
 **/
export const c = (key: string, values?: Record<string, unknown>) =>
  t(`component:${key}`, values)
