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 const languages = __LANGS__.map((key) => ({
  key,
  label: key.toUpperCase(),
}));

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,
        },
      });
  },
};
