import 'server-only'

const dictionaries = {
  fa: (namespace: string) => import(`@/dictionaries/fa/${namespace}.json`).then((module) => module.default),
  en: (namespace: string) => import(`@/dictionaries/en/${namespace}.json`).then((module) => module.default),
}

export const getDictionary = async (
  locale: 'en' | 'fa',
  namespace: 'common' | 'module'
) => {
  try {
    return await dictionaries[locale](namespace)
  } catch (error) {
    console.error(`Failed to load ${locale}/${namespace}.json`, error)
    return {}
  }
}
