/**
 * TabataFit i18n Setup
 * expo-localization + i18next + react-i18next
 * Auto-detects device locale, falls back to English
 */

import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import { getLocales } from 'expo-localization'

// EN
import enCommon from './locales/en/common.json'
import enScreens from './locales/en/screens.json'
import enContent from './locales/en/content.json'
import enNotifications from './locales/en/notifications.json'

// FR
import frCommon from './locales/fr/common.json'
import frScreens from './locales/fr/screens.json'
import frContent from './locales/fr/content.json'
import frNotifications from './locales/fr/notifications.json'

// ES
import esCommon from './locales/es/common.json'
import esScreens from './locales/es/screens.json'
import esContent from './locales/es/content.json'
import esNotifications from './locales/es/notifications.json'

// DE
import deCommon from './locales/de/common.json'
import deScreens from './locales/de/screens.json'
import deContent from './locales/de/content.json'
import deNotifications from './locales/de/notifications.json'

const deviceLanguage = getLocales()[0]?.languageCode ?? 'en'

i18n
  .use(initReactI18next)
  .init({
    compatibilityJSON: 'v4',
    lng: deviceLanguage,
    fallbackLng: 'en',
    ns: ['common', 'screens', 'content', 'notifications'],
    defaultNS: 'common',
    resources: {
      en: {
        common: enCommon,
        screens: enScreens,
        content: enContent,
        notifications: enNotifications,
      },
      fr: {
        common: frCommon,
        screens: frScreens,
        content: frContent,
        notifications: frNotifications,
      },
      es: {
        common: esCommon,
        screens: esScreens,
        content: esContent,
        notifications: esNotifications,
      },
      de: {
        common: deCommon,
        screens: deScreens,
        content: deContent,
        notifications: deNotifications,
      },
    },
    interpolation: {
      escapeValue: false,
    },
  })

export default i18n
