import { createI18n } from 'vue-i18n';
import '../api/index.mjs';
import de_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/de.mjs';
import en_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/en.mjs';
import es_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/es.mjs';
import fi_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/fi.mjs';
import fr_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/fr.mjs';
import it_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/it.mjs';
import ja_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/ja.mjs';
import ko_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/ko.mjs';
import no_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/no.mjs';
import pl_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/pl.mjs';
import pt_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/pt.mjs';
import ru_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/ru.mjs';
import zh_cn_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/zh-cn.mjs';
import zh_tw_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/zh-tw.mjs';
import th_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/th.mjs';
import id_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/id.mjs';
import ms_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/ms.mjs';
import vi_default from '../../node_modules/.pnpm/element-plus@2.14.0_vue@3.5.35_typescript@6.0.3_/node_modules/element-plus/es/locale/lang/vi.mjs';
import msMY from '../../_virtual/en-US.mjs';
import deDE from '../../_virtual/de-DE.mjs';
import esES from '../../_virtual/es-ES.mjs';
import frFR from '../../_virtual/fr-FR.mjs';
import itIT from '../../_virtual/it-IT.mjs';
import jaJP from '../../_virtual/ja-JP.mjs';
import koKR from '../../_virtual/ko-KR.mjs';
import noNO from '../../_virtual/nb-NO.mjs';
import ptBR from '../../_virtual/pt-BR.mjs';
import ruRU from '../../_virtual/ru-RU.mjs';
import zhCN from '../../_virtual/zh-CN.mjs';
import zhHK from '../../_virtual/zh-HK.mjs';
import zhTW from '../../_virtual/zh-TW.mjs';
import thTH from '../../_virtual/th-TH.mjs';
import viVN from '../../_virtual/vi-VN.mjs';
export { default as en } from './lang/en.mjs';
export { default as zhCn } from './lang/zh-cn.mjs';
import { useBaseApi } from '../api/base/index.mjs';

const messages = {};
const element = {
  "zh-CN": zh_cn_default,
  "zh-TW": zh_tw_default,
  "zh-HK": zh_tw_default,
  en: en_default,
  de: de_default,
  es: es_default,
  fi: fi_default,
  fr: fr_default,
  it: it_default,
  ja: ja_default,
  ko: ko_default,
  no: no_default,
  pl: pl_default,
  pt: pt_default,
  ru: ru_default,
  th: th_default,
  id: id_default,
  ms: ms_default,
  vi: vi_default
};
const vxe = {
  "zh-CN": zhCN,
  "zh-TW": zhTW,
  "zh-HK": zhHK,
  en: msMY,
  de: deDE,
  es: esES,
  fi: msMY,
  fr: frFR,
  it: itIT,
  ja: jaJP,
  ko: koKR,
  no: noNO,
  pl: msMY,
  pt: ptBR,
  ru: ruRU,
  th: thTH,
  id: msMY,
  ms: msMY,
  vi: viVN
};
const languageList = {
  "zh-CN": "\u7B80\u4F53\u4E2D\u6587",
  // 'zh-TW': '繁體中文(台灣)',
  // 'zh-HK': '繁體中文(香港)',
  en: "English"
  // de: 'Deutsch',
  // es: 'Español',
  // fi: 'Suomeksi',
  // fr: 'Français',
  // it: 'Italiano',
  // ja: '日本語',
  // ko: '한국어',
  // no: 'Norsk',
  // pl: 'Polski',
  // pt: 'Português',
  // ru: 'Русский',
  // th: 'ไทย',
  // id: 'Indonesia',
  // ms: 'Malaysia',
  // vi: 'Việt Nam',
};
const iso_3166_1_CountryList = {
  de: "de",
  en: "us",
  es: "es",
  fi: "fi",
  fr: "fr",
  it: "it",
  ja: "jp",
  ko: "kr",
  no: "no",
  pl: "pl",
  pt: "pt",
  ru: "ru",
  "zh-CN": "cn",
  "zh-TW": "tw",
  "zh-HK": "hk",
  th: "th",
  id: "id",
  ms: "ms",
  vi: "vi"
};
const itemize = { en: [], "zh-CN": [], "zh-TW": [], "zh-HK": [], de: [], es: [], fi: [], fr: [], it: [], ja: [], ko: [], no: [], pl: [], pt: [], ru: [], th: [], id: [], ms: [], vi: [] };
const getCountryCode = (locale) => {
  return iso_3166_1_CountryList[locale];
};
function mergeArrObj(list, key) {
  let obj = {};
  list[key].forEach((i) => {
    obj = Object.assign({}, obj, i);
  });
  return obj;
}
const i18n = createI18n({
  legacy: false,
  silentTranslationWarn: true,
  missingWarn: false,
  silentFallbackWarn: true,
  fallbackWarn: false,
  locale: "zh-CN",
  fallbackLocale: "zh-CN",
  messages: {},
  globalInjection: true,
  fallbackFormat: false,
  // 关闭默认的 fallback 行为
  missing: (locale, key) => {
    const lastPart = key.includes(".") ? key.split(".").pop() : key;
    return lastPart.replace(/\${(.+?)}/g, "$1");
  }
});
async function mergMessage(lang, msg) {
  i18n.global.mergeLocaleMessage(lang, msg);
}
async function loadRemoteMessages(teanId) {
  const res = await useBaseApi("sysLanguagePack").get(null, "lgpk/" + teanId);
  const data = res.data.result;
  i18n.global.mergeLocaleMessage("zh-CN", {
    message: {
      menu: data.mencn
    }
  });
  i18n.global.mergeLocaleMessage("en", {
    message: {
      menu: data.menen
    }
  });
}
async function loadLocaleMessages(tempmodel) {
  for (const path in tempmodel) {
    const key = path.match(/(\S+)\/(\S+).ts/);
    if (itemize[key[2]]) itemize[key[2]].push(tempmodel[path].default);
    else itemize[key[2]] = tempmodel[path];
  }
  for (const key in itemize) {
    messages[key] = {
      name: key,
      el: element[key].el,
      message: mergeArrObj(itemize, key),
      vxe: vxe[key].vxe
    };
    i18n.global.setLocaleMessage(key, messages[key]);
  }
}
async function setupI18n(app, tempmodel, lang) {
  await loadLocaleMessages(tempmodel);
  i18n.global.locale.value = lang;
  app.use(i18n);
  i18n.global.setMissingHandler((locale, key) => {
    if (key.includes(".")) {
      console.warn(
        `[intlify] Not found '${key}' key in '${locale}' locale messages.`
      );
    }
  });
}

export { getCountryCode, i18n, iso_3166_1_CountryList, languageList, loadRemoteMessages, mergMessage, setupI18n };
