import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

// English
import enCommon from './locales/en/common.json';
import enSidebar from './locales/en/sidebar.json';
import enTopbar from './locales/en/topbar.json';
import enAuth from './locales/en/auth.json';
import enSettings from './locales/en/settings.json';
import enDashboard from './locales/en/dashboard.json';
import enServers from './locales/en/servers.json';
import enAgentConfig from './locales/en/agent-config.json';
import enSecurity from './locales/en/security.json';
import enMonitoring from './locales/en/monitoring.json';
import enAudit from './locales/en/audit.json';
import enCommunication from './locales/en/communication.json';
import enTenants from './locales/en/tenants.json';
import enUsers from './locales/en/users.json';
import enTerminal from './locales/en/terminal.json';
import enStandingOrders from './locales/en/standing-orders.json';
import enRunbooks from './locales/en/runbooks.json';
import enSessions from './locales/en/sessions.json';
import enBilling from './locales/en/billing.json';

// Chinese
import zhCommon from './locales/zh/common.json';
import zhSidebar from './locales/zh/sidebar.json';
import zhTopbar from './locales/zh/topbar.json';
import zhAuth from './locales/zh/auth.json';
import zhSettings from './locales/zh/settings.json';
import zhDashboard from './locales/zh/dashboard.json';
import zhServers from './locales/zh/servers.json';
import zhAgentConfig from './locales/zh/agent-config.json';
import zhSecurity from './locales/zh/security.json';
import zhMonitoring from './locales/zh/monitoring.json';
import zhAudit from './locales/zh/audit.json';
import zhCommunication from './locales/zh/communication.json';
import zhTenants from './locales/zh/tenants.json';
import zhUsers from './locales/zh/users.json';
import zhTerminal from './locales/zh/terminal.json';
import zhStandingOrders from './locales/zh/standing-orders.json';
import zhRunbooks from './locales/zh/runbooks.json';
import zhSessions from './locales/zh/sessions.json';
import zhBilling from './locales/zh/billing.json';

export const supportedLngs = ['en', 'zh'] as const;
export type SupportedLocale = (typeof supportedLngs)[number];

i18n
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    resources: {
      en: {
        common: enCommon,
        sidebar: enSidebar,
        topbar: enTopbar,
        auth: enAuth,
        settings: enSettings,
        dashboard: enDashboard,
        servers: enServers,
        'agent-config': enAgentConfig,
        security: enSecurity,
        monitoring: enMonitoring,
        audit: enAudit,
        communication: enCommunication,
        tenants: enTenants,
        users: enUsers,
        terminal: enTerminal,
        'standing-orders': enStandingOrders,
        runbooks: enRunbooks,
        sessions: enSessions,
        billing: enBilling,
      },
      zh: {
        common: zhCommon,
        sidebar: zhSidebar,
        topbar: zhTopbar,
        auth: zhAuth,
        settings: zhSettings,
        dashboard: zhDashboard,
        servers: zhServers,
        'agent-config': zhAgentConfig,
        security: zhSecurity,
        monitoring: zhMonitoring,
        audit: zhAudit,
        communication: zhCommunication,
        tenants: zhTenants,
        users: zhUsers,
        terminal: zhTerminal,
        'standing-orders': zhStandingOrders,
        runbooks: zhRunbooks,
        sessions: zhSessions,
        billing: zhBilling,
      },
    },
    fallbackLng: 'en',
    defaultNS: 'common',
    supportedLngs: [...supportedLngs],
    interpolation: {
      escapeValue: false,
    },
    detection: {
      order: ['localStorage', 'navigator'],
      lookupLocalStorage: 'it0-locale',
      caches: [],
    },
  });

export default i18n;
