<template>
  <el-config-provider :locale="locale_el">
    <router-view />
  </el-config-provider>
</template>

<script setup>
import ru from "element-plus/dist/locale/ru";
import zhCn from "element-plus/dist/locale/zh-cn";
import useSettingsStore from "@/store/modules/settings";
import { handleThemeStyle } from "@/utils/theme";
import { computed, watch } from "vue";
import { useI18n } from "vue-i18n";

const settingsStore = useSettingsStore();
const { locale } = useI18n();

const locale_el = computed(() => {
  let locale = zhCn;
  if (settingsStore.locale === "zh") {
    locale = zhCn;
  } else if (settingsStore.locale === "ru") {
    locale = ru;
  }
  return locale;
});

watch(
  () => settingsStore.locale,
  (newVal) => {
    locale.value = newVal;
  },
  { immediate: true },
);

onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme);
  });
});
</script>
