import { createI18n } from 'vue-i18n';
import store from '../store/index.js';

import enGeneral from './locales/en/general.json';
import enHeader from './locales/en/header.json';
import enNavigation from './locales/en/navigation.json';
import enHome from './locales/en/home.json';
import enChat from './locales/en/chat.json';
import enRegister from './locales/en/register.json';
import enError from './locales/en/error.json';
import enActivate from './locales/en/activate.json';
import enSettings from './locales/en/settings.json';
import enAdmin from './locales/en/admin.json';
import enSocialNetwork from './locales/en/socialnetwork.json';
import enFriends from './locales/en/friends.json';
import enFalukant from './locales/en/falukant.json';
import enPasswordReset from './locales/en/passwordReset.json';
import enBlog from './locales/en/blog.json';
import enMinigames from './locales/en/minigames.json';
import enMessage from './locales/en/message.json';

import deGeneral from './locales/de/general.json';
import deHeader from './locales/de/header.json'; 
import deNavigation from './locales/de/navigation.json';
import deHome from './locales/de/home.json';
import deChat from './locales/de/chat.json';
import deRegister from './locales/de/register.json';
import deError from './locales/de/error.json';
import deActivate from './locales/de/activate.json';
import deSettings from './locales/de/settings.json';
import deAdmin from './locales/de/admin.json';
import deSocialNetwork from './locales/de/socialnetwork.json';
import deFriends from './locales/de/friends.json';
import deFalukant from './locales/de/falukant.json';
import dePasswordReset from './locales/de/passwordReset.json';
import deBlog from './locales/de/blog.json';
import deMinigames from './locales/de/minigames.json';
import deMessage from './locales/de/message.json';

const messages = {
  en: {
    ...enGeneral,
    ...enHeader,
    ...enNavigation,
    ...enHome,
    ...enChat,
    ...enRegister,
    ...enPasswordReset,
    ...enError,
    ...enActivate,
    ...enSettings,
    ...enAdmin,
    ...enSocialNetwork,
    ...enFriends,
    ...enFalukant,
    ...enBlog,
    ...enMinigames,
    ...enMessage,
  },
  de: {
    'Ok': 'Ok',
    ...deGeneral,
    ...deHeader,
    ...deNavigation,
    ...deHome,
    ...deChat,
    ...deRegister,
    ...dePasswordReset,
    ...deError,
    ...deActivate,
    ...deSettings,
    ...deAdmin,
    ...deSocialNetwork,
    ...deFriends,
    ...deFalukant,
    ...deBlog,
    ...deMinigames,
    ...deMessage,
  }
};

const i18n = createI18n({
  locale: store.state.language,
  fallbackLocale: 'de',
  messages
});

// Überwache Änderungen der Sprache im Store und aktualisiere i18n entsprechend
store.watch(
  (state) => state.language,
  (newLanguage) => {
    i18n.global.locale.value = newLanguage;
  }
);

export default i18n;
