import { useCallback, useMemo, createContext, useContext } from 'react';

const useTranslations = (translations) => {
  const t = useCallback(
    (key) => {
      try {
        const val = key.split(".").reduce(
          (currentTranslationSubtree, currentKey) => {
            if (!currentTranslationSubtree) {
              throw new Error("no such translation available");
            }
            if (typeof currentTranslationSubtree === "string") {
              throw new Error("no such translation available");
            }
            return currentTranslationSubtree?.[currentKey];
          },
          translations
        );
        if (typeof val === "string") {
          return val;
        }
        return key;
      } catch {
        console.warn(`No such translation key exists: ${key}`);
        return key;
      }
    },
    [translations]
  );
  return useMemo(() => ({ translations: t }), [t]);
};

const defaultContext = {
  locale: "en",
  t: (value) => value
};
const LocalizationContext = createContext(defaultContext);
const useLocalizationContext = () => useContext(LocalizationContext);

export { LocalizationContext as L, useTranslations as a, useLocalizationContext as u };
//# sourceMappingURL=LocalizationContext-UsmB5mnR.js.map
