import i18next from "i18next";
import Backend, { type HttpBackendOptions } from "i18next-http-backend";
import { initReactI18next } from "react-i18next";

declare const __LANGS__: string[];
declare const __LOCALES_PATH__: string;
declare const __DEFAULT_LANG__: string;

export type { Language } from "./languages";
export { languages } from "./languages";
export { useLanguages } from "./useLanguages";

export default {
  init() {
    i18next
      .use(Backend)
      .use(initReactI18next)
      .init<HttpBackendOptions>({
        backend: {
          loadPath: `/${__LOCALES_PATH__}/{{lng}}.json`,
        },
        fallbackLng: __DEFAULT_LANG__,
        supportedLngs: __LANGS__,
        debug: import.meta.env.DEV,
        interpolation: {
          escapeValue: false,
        },
      });
  },
};
